智商是硬伤啊,昨天在华为做了一道简单的递归都没写出来,尼玛,现在想想实在是愚蠢至极,还特么想拿华为当垫脚石,递归都不会
class Solution {
public:
TreeNode *sortedArrayToBST(vector<int> &num) {
return sorta(num,0,num.size()-1);
}
TreeNode *sorta(vector<int>&num,int start,int end)
{
if(start>end)
return NULL;
int mid=(start+end)/2;
TreeNode *root=new TreeNode(num[mid]);
root->left=sorta(num,start,mid-1);
root->right=sorta(num,mid+1,end);
return root;
}
};