Leetcode 108. Convert Sorted Array to Binary Search Tree
2017-01-20 10:45
501 查看
public class Solution { public TreeNode sortedArrayToBST(int[] nums) { return helper(0, nums.length-1, nums); } // requires a balanced binary search tree, every time choosing mid of the array as root public static TreeNode helper(int low, int high, int[] nums) { if (low > high) return null; int mid = low + (high-low)/2; TreeNode root = new TreeNode(nums[mid]); root.left = helper(low, mid-1, nums);; root.right = helper(mid+1, high, nums);; return root; } }
相关文章推荐
- JS中this的四种用法
- jxl操作xls文档小结
- Linux内核哈希表分析与应用
- No grammar constraints (DTD or XML schema).....两种解决方法
- Java 定时任务
- 分布式数据集RDD经典集锦
- navicat不能创建函数
- 深入理解PowerManagerService
- rece_2
- EL表达式截取字符串
- java中获取当前日期和时间的方法
- PHP7.1新特性一览
- 安装ipython时python setup.py egg_info错误的解决办法
- 2017寒假阅读笔记01
- Python基础学习笔记
- Docker安装和简单使用入门教程
- TCP、UDP、IP 协议分析
- 嵌入式培训的骗局这些事你怎么看?
- 【Android】AlertDialog中的EditText不能弹出软键盘的问题
- adb devices offline solution for Window Batch CMD