题干:

代码:
class Solution {
public:
TreeNode* traversal(vector<int>& nums, int left, int right){
if(left > right)return NULL;
int mid = left + (right - left)/2;
TreeNode* NewRoot = new TreeNode(nums[mid]);
NewRoot->left = traversal(nums, left, mid-1);
NewRoot->right = traversal(nums, mid+1,right);
return NewRoot;
}
TreeNode* sortedArrayToBST(vector<int>& nums) {
int left = 0;
int right = nums.size()-1;
return traversal(nums, left, right);
}
};
采取左闭右闭的区间划分方式。

一开始少了这一行导致了栈溢出。






![[python:django]:web框架搭建项目](https://img-blog.csdnimg.cn/direct/193b5c513a904b28a648c3529dd8ddde.png)



![[蓝桥杯]真题讲解:合并数列(双指针+贪心)](https://img-blog.csdnimg.cn/direct/e26e6d2185fe4561bf107ed0eac4694f.png)




![YOLOv8训练流程-原理解析[目标检测理论篇]](https://img-blog.csdnimg.cn/direct/a358c400b05b45cca1d63ca631eab1fc.png)

![[C/C++] -- 大数的加减法](https://img-blog.csdnimg.cn/direct/211a7346d99a4fa09f3d1f286b1d8340.png)