//vec 构造函数 vec.begin() end() + num ={134} =other vector
//一直到null 就行 new(int) root->left ->right
// 树 递归 层序遍历
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
TreeNode* sortedArrayToBST(vector<int>& nums) {
if(nums.empty())
return nullptr;
TreeNode * root = new TreeNode(nums[nums.size()/2]);
vector<int> left_vec = vector<int>(nums.begin(),nums.begin() + nums.size()/2);
vector<int> right_vec = vector<int>(nums.begin() + nums.size()/2 +1,nums.end());
root->left = sortedArrayToBST(left_vec);
root->right = sortedArrayToBST(right_vec);
return root;
}
};