标签:length rsa highlight new ons public solution from uil
public class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { return buildTree(preorder, 0, preorder.length-1, inorder, 0, inorder.length); } private TreeNode buildTree(int[] preorder, int l1, int r1, int[] inorder, int l2, int r2){ if(l1>r1||l2>r2) return null; int idx=l2; while(inorder[idx]!=preorder[l1]) idx++; TreeNode node=new TreeNode(preorder[l1]); node.left=buildTree(preorder, l1+1, l1+(idx-l2), inorder, l2, idx-1); node.right=buildTree(preorder, l1+(idx-l2)+1, r1, inorder, idx+1, r2); return node; } }
105. Construct Binary Tree from Preorder and Inorder Traversal
标签:length rsa highlight new ons public solution from uil
原文地址:http://www.cnblogs.com/asuran/p/7610496.html