Here is my Java solution, use the ideas of quick sorting.

```
public class Solution {
public TreeNode sortedArrayToBST(int[] nums) {
if (nums.length==0)
return null;
int k= (nums.length)/2;
TreeNode root= new TreeNode(nums[k]);
root.left=sortedArrayToBST(Arrays.copyOfRange(nums, 0, k));
root.right=sortedArrayToBST(Arrays.copyOfRange(nums, k+1,nums.length));
return root;
}
}
```