标签:int div 遍历 art class span 前序遍历 ret tle
public Node reConstructBinaryTree(int[] pre,int[] in){ if(pre==null || in ==null){ return null; } Node mm = reConstructBinaryTree(pre,in,0,pre.length-1,0,in.length-1); return mm; } public Node reConstructBinaryTree(int[] pre,int[] in,int preStart,int preEnd,int inStart,int inEnd){ Node node = new Node(pre[preStart]); node.left = null; node.right = null; if(preStart == preEnd && inStart == inEnd){ return node; } int root = 0; for(root = instart;root<inEnd;root++){ if(pre[preStart] == in[root]){ break; } } int leftLength = root-inStart; int rightLength = inEnd-root; if(leftLength>0){ node.left = reConstructBinaryTree(pre,in,preStart+1,preStart+leftLength,inStart,root-1); } if(rightLength>0){ node.right = reConstructBinaryTree(pre,in,preStart+leftLength,root+1,inEnd); } return node; }
标签:int div 遍历 art class span 前序遍历 ret tle
原文地址:https://www.cnblogs.com/yingpu/p/9281912.html