My Accepted Java Solution
Hi everyone, this is my accepted recursive Java solution. I get overflow problems at first because I didn't use mid - 1 and mid + 1 as the bound. Hope this help
Hi everyone, this is my accepted recursive Java solution. I get overflow problems at first because I didn't use mid - 1 and mid + 1 as the bound. Hope this helps :)\n\n    public TreeNode sortedArrayToBST(int[] num) {\n        if (num.length == 0) {\n            return null;\n        }\n        TreeNode head = helper(num, 0, num.length - 1);\n        return head;\n    }\n    \n    public TreeNode helper(int[] num, int low, int high) {\n        if (low > high) { // Done\n            return null;\n        }\n        int mid = (low + high) / 2;\n        TreeNode node = new TreeNode(num[mid]);\n        node.left = helper(num, low, mid - 1);\n        node.right = helper(num, mid + 1, high);\n        return node;\n    }
[]