package LeetCode.OneToFiveHundred;
import LeetCode.TreeNode;
public class OneHundredAndEight {
public TreeNode sortedArrayToBST(int[] nums) {
return inverseMiddleOrderTraversal(nums ,0 , nums.length - 1);
}
private TreeNode inverseMiddleOrderTraversal(int nums[], int left, int right){
if (left > right) return null;
int mid = (left + right) / 2;
TreeNode root = new TreeNode(nums[mid]);
root.left = inverseMiddleOrderTraversal(nums, left, mid - 1);
root.right = inverseMiddleOrderTraversal(nums, mid + 1, right);
return root;
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-52761.html