🟢Beats 100.00% of users with Java, Easy Solution with Explanation
Keep growing \uD83D\uDE0A\n\n\n\n# Complexity\n\n- Time complexity: O(N)\n\n- Space complexity: O(log N)\n\n\n# Explanation\n\nJavascript []\nStart\nCall \'bst\
##### Keep growing \uD83D\uDE0A\n![image.png](https://assets.leetcode.com/users/images/38469369-a866-40b3-ae2a-6a01affac03b_1706593071.011844.png)\n\n\n# Complexity\n\n- Time complexity: O(N)\n\n- Space complexity: O(log N)\n\n\n# Explanation\n\n```Javascript []\nStart\nCall \'bst\' with arguments \'nums\', 0, and \'nums.length - 1\', and return the result.\n\nFunction \'bst\' with arguments \'nums\', \'start\', and \'end\'\n    If \'start\' is greater than \'end\'\n        Return null\n\n    Calculate \'mid\' as the integer division of the sum of \'start\' and \'end\' by 2\n    Create a new TreeNode \'node\' with the value \'nums[mid]\'\n    Set \'node.left\' to the result of the recursive call to \'bst\' with arguments \'nums\', \'start\', and \'mid - 1\'\n    Set \'node.right\' to the result of the recursive call to \'bst\' with arguments \'nums\', \'mid + 1\', and \'end\'\n    Return \'node\'\nEnd\n```\n\n# Code\n\n```java []\nclass Solution {\n    public TreeNode sortedArrayToBST(int[] nums) {\n        return bst(nums, 0, nums.length - 1);\n    }\n\n    TreeNode bst(int[] nums, int start, int end) {\n        if (start > end) {\n            return null;\n        }\n        int mid = (start + end) / 2;\n        TreeNode node = new TreeNode(nums[mid]);\n        node.left = bst(nums, start, mid - 1);\n        node.right = bst(nums, mid + 1, end);\n        return node;\n    }\n}\n```\n##### If you have any question, feel free to ask. If you like the solution or the explanation, Please UPVOTE ! \u270C\uFE0F
['Array', 'Divide and Conquer', 'Tree', 'Binary Search Tree', 'Binary Tree', 'Java']