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