Both java versions are borked (openjdk7 and java 8 array support)


#1

For both, the test reported that the results of my code for input [1] were preorder [1] and postorder [1], but expected inorder [1]. ??


#2

same here.
There is no java solution proposed for Java 8 or Java Array.
However this solution is proposed for cpp

TreeNode* helper(vector<int> &num, int low, int high) {
        if (low > high) { // Done
            return NULL;
        }
        int mid = (low + high) / 2;
        TreeNode* node = new TreeNode(num[mid]);
        node->left = helper(num, low, mid - 1);
        node->right = helper(num, mid + 1, high);
        return node;
    }

    TreeNode *sortedArrayToBST(vector<int> &num) {
        if (num.size() == 0) return NULL;
        return helper(num, 0, ((int)num.size()) - 1);
    }

#3

for java just change the function parameter to following

public TreeNode sortedArrayToBST(final List<Integer> A) {}

it will work, and will pass all test cases, there is bug


#4

It just works for jdk 7.