2014年1月20日

LeetCode: Convert Sorted Array & List to Binary Search Tree

摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.递归。找到数组的中点作为root,左边递归构造左子树,右边递归构造右子树。条件判断有点写重复了。。。 1 public TreeNode sortedArrayToBST(int[] num) { 2 if (num.length == 0) return null; 3 else if (num.length == 1) return new TreeNode(num[... 阅读全文

posted @ 2014-01-20 21:11 longhorn 阅读(148) 评论(0) 推荐(0) 编辑

导航