108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree
Description
Given an integer array nums
where the elements are sorted in ascending order , convert it to a height-balanced binary search tree.
Example 1:
![](https://assets.leetcode.com/uploads/2021/02/18/btree1.jpg)
1 | Input: nums = [-10,-3,0,5,9] |
Explanation: [0,-10,5,null,-3,null,9] is also accepted:
![](https://assets.leetcode.com/uploads/2021/02/18/btree2.jpg)
Example 2:
![](https://assets.leetcode.com/uploads/2021/02/18/btree.jpg)
1 | Input: nums = [1,3] |
Constraints:
1 <= nums.length <= 10^4
-10^4 <= nums[i] <= 10^4
nums
is sorted in a strictly increasing order.
Hints/Notes
- 2024/07/05
- binary search tree
- No solution from 0x3F
Solution
Language: C++
1 | /** |