```
public TreeNode SortedArrayToBST(int[] nums) {
return Partition(nums, 0, nums.Length - 1);
}
public TreeNode Partition(int[] nums, int left, int right)
{
if (right < left) return null;
int mid = (left + right)/2;
TreeNode root = new TreeNode(nums[mid]);
root.left = Partition(nums, left, mid - 1);
root.right = Partition(nums, mid + 1, right);
return root;
}
```