import java.util.*;

/*
 * public class TreeNode {
 *   int val = 0;
 *   TreeNode left = null;
 *   TreeNode right = null;
 * }
 */
public class Solution {
    /**
     * 
     * @param num int整型一维数组 
     * @return TreeNode类
     */
    public TreeNode F (int[] num,int left,int right) {
        
        if(left>right) return null;
        int mid = (int) Math.round((right+left*1.0)/2); //特意把里面的变成double型
        int val = num[mid];
        TreeNode root = new TreeNode(val);
         if(left==right) return root;
        root.left = F(num,left,mid-1);
        root.right = F(num,mid+1,right);
        return root;
        
    }
    public TreeNode sortedArrayToBST (int[] num) {
        // write code here
        if(num.length<=0) return null;
        return F(num,0,num.length-1);
        
    }
}