Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public TreeNode sortedArrayToBST(int[] num) {
- if(num.length==0){
- return null;
- }
- TreeNode head = helper(num,0,num.length-1);
- return head;
- }
- public TreeNode helper(int[] num, int low , int high){
- if(low>high){
- return null;
- }
- int mid = low+(high-low)/2;
- TreeNode node = new TreeNode(num[mid]);
- node.left = helper(num,low,mid-1);
- node.right = helper(num,mid+1,high);
- return node;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement