🔥✅✅ Mastering Efficiency: Beat 89.74% ✅✅🔥
\n\n\n\n\npython []\nclass Solution(object):\n    def sortedArrayToBST(self, nums):\n        def helper(start, end):\n            if start > end:\n             
![31c8f335-9e52-45bd-8701-8f33260b84ad_1709165793.521128.png](https://assets.leetcode.com/users/images/c1ee5054-dd07-4caa-a7df-e21647cfae9e_1709942227.5165014.png)\n\n[![Screen Shot 2024-03-12 at 19.03.05.png](https://assets.leetcode.com/users/images/59f66847-9733-40aa-8fe1-47df8e38c3f6_1710252200.8441794.png)](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/submissions/1201555699)\n\n\n```python []\nclass Solution(object):\n    def sortedArrayToBST(self, nums):\n        def helper(start, end):\n            if start > end:\n                return None\n            mid = (start + end) // 2\n            root = TreeNode(nums[mid])\n            root.left = helper(start, mid - 1)\n            root.right = helper(mid + 1, end)\n            return root\n\n        return helper(0, len(nums) - 1)\n```\n```python3 []\nclass Solution:\n    def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]:\n        def helper(start, end):\n            if start > end:\n                return None\n            mid = (start + end) // 2\n            root = TreeNode(nums[mid])\n            root.left = helper(start, mid - 1)\n            root.right = helper(mid + 1, end)\n            return root\n\n        return helper(0, len(nums) - 1)\n```\n```C++ []\nclass Solution {\npublic:\n    TreeNode* sortedArrayToBST(vector<int>& nums) {\n        return sortedArrayToBSTHelper(nums, 0, nums.size() - 1);\n    }\n\nprivate:\n    TreeNode* sortedArrayToBSTHelper(const vector<int>& nums, int start, int end) {\n        if (start > end) {\n            return nullptr;\n        }\n        int mid = start + (end - start) / 2;\n        TreeNode* root = new TreeNode(nums[mid]);\n        root->left = sortedArrayToBSTHelper(nums, start, mid - 1);\n        root->right = sortedArrayToBSTHelper(nums, mid + 1, end);\n        return root;\n    }\n};\n```\n```javascript []\nvar sortedArrayToBST = function(nums) {\n    const helper = (start, end) => {\n        if (start > end) {\n            return null;\n        }\n        const mid = Math.floor((start + end) / 2);\n        const root = new TreeNode(nums[mid]);\n        root.left = helper(start, mid - 1);\n        root.right = helper(mid + 1, end);\n        return root;\n    };\n\n    return helper(0, nums.length - 1);\n};\n```\n\n\n![Glenn Radars_9 2 4 2.png](https://assets.leetcode.com/users/images/c2c8fe57-160f-42c0-a57a-a543d9ca335a_1709601428.5689478.png)\n\n## **My solutions**\n\n\uD83D\uDFE2 - $$easy$$  \n\uD83D\uDFE1 - $$medium$$ \n\uD83D\uDD34 - $$hard$$\n\n\uD83D\uDFE1 [46. Permutations](https://leetcode.com/problems/permutations/solutions/4853218/beat-98-64-full-explanation-with-pictures)\n\uD83D\uDFE1 [17. Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/solutions/4845532/there-is-an-80-chance-of-being-in-the-interview-full-problem-explanation)\n\uD83D\uDFE1 [22. Generate Parentheses](https://leetcode.com/problems/generate-parentheses/solutions/4845742/simple-explanation-with-pictures)\n\uD83D\uDFE1 [39. Combination Sum](https://leetcode.com/problems/combination-sum/solutions/4847482/beat-8292-full-explanation-with-pictures)\n\uD83D\uDFE2 [2540. Minimum Common Value](https://leetcode.com/problems/minimum-common-value/solutions/4845076/beat-9759-full-explanation-with-pictures)\n\uD83D\uDFE2 [3005. Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency/solutions/4839796/beat-8369-full-explanation-with-pictures)\n\uD83D\uDFE2 [3028. Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary/solutions/4837433/full-explanation-with-pictures)\n\uD83D\uDFE2 [876. Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/solutions/4834682/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [1750. Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/solutions/4824224/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [948. Bag of Tokens](https://leetcode.com/problems/bag-of-tokens/solutions/4818912/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/solutions/4813340/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE2 [977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/solutions/4807704/square-sorter-python-python3-javascript-c)\n\uD83D\uDFE2 [2864. Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/solutions/4802402/visual-max-odd-binary-solver-python-python3-javascript-c)\n\uD83D\uDFE1 [1609. Even Odd Tree](https://leetcode.com/problems/even-odd-tree/solutions/4797529/even-odd-tree-validator-python-python3-javascript-c)\n\uD83D\uDFE2 [9. Palindrome Number](https://leetcode.com/problems/palindrome-number/solutions/4795373/why-not-1-line-of-code-python-python3-c-everyone-can-understand)\n\uD83D\uDFE1 [513. Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value/solutions/4792022/binary-tree-explorer-mastered-javascript-python-python3-c-10000-efficiency-seeker)\n\uD83D\uDFE2 [1. Two Sum](https://leetcode.com/problems/two-sum/solutions/4791305/5-methods-python-c-python3-from-easy-to-difficult)\n\uD83D\uDFE2 [543. Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/solutions/4787634/surpassing-9793-memory-magician-excelling-at-9723)\n\uD83D\uDFE2 [101. Symmetric Tree](https://leetcode.com/problems/symmetric-tree/solutions/4848126/beat-100-full-explanation-with-pictures)\n\uD83D\uDFE2 [136. Single Number](https://leetcode.com/problems/single-number/solutions/4862807/master-the-xor-trick-beat-97-20-with-full-explanation)\n\uD83D\uDFE2 [283. Move Zeroes](https://leetcode.com/problems/move-zeroes/solutions/4864068/mastering-efficiency-beat-98-71)\n\uD83D\uDFE2 [108. Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/solutions/4864578/beat-89-74-full-explanation-with-pictures)\n\n[More...](https://leetcode.com/DevOgabek/)
['Array', 'Divide and Conquer', 'Tree', 'Binary Search Tree', 'Binary Tree', 'Python', 'C++', 'Python3', 'JavaScript']