public TreeNode toArray(int[] num, int start, int end) {
        if (start > end) {
            return null;
        } else if (start == end) {
            return new TreeNode(num[start]);
        } else {
            int mid = (start + end) / 2;
            TreeNode root = new TreeNode(num[mid]);
            root.left = toArray(num, start, mid - 1);
            root.right = toArray(num, mid + 1, end);
            return root;
        }
    }