登录
  • #刷题

求问‌‌‌‍‌‌‍‌‍‌‌‍‌‌‌‌‌‍‌‌‍‌‍‍‍‍‌‍‌‍‌‍ leetcode449题 serialize and Deserialize BST

yanyan80
287
0
代码如下:输入[2,1,3],运行结果是[0,0,0].

class Solution {

int index,N;

int[] preorder;[br]
public TreeNode helper(int[] preorder) {[br]
this.preorder=preorder;N=preorder.length;

return helper(Integer.MIN_VALUE,Integer.MAX_VALUE);

}

public TreeNode helper(int lower,int upper) {

if(index==N) return null;

int val=preorder[index];

if(val<lower||val>upper) return null;

index++;

TreeNode root=new TreeNode(val);

root.left=helper(lower,val);

root.right=helper(val,upper);

return root;

}

}
0条回复
热度排序

发表回复