[Cpp]
Struct TreeNode {
Int val;
TreeNode * left;
TreeNode * right;
TreeNode (int x): val (x), left (NULL), right (NULL ){}
};
Class Solution {
Public:
TreeNode * Convert2BST (vector <int> & num, int start, int end)
{
If (start> end)
Return NULL;
Int mid = (start + end)/2;
TreeNode * pNode = new TreeNode (num [mid]);
PNode-> left = Convert2BST (num, start, mid-1 );
PNode-> right = Convert2BST (num, mid + 1, end );
Return pNode;
}
TreeNode * sortedArrayToBST (vector <int> & num ){
// Start typing your C/C ++ solution below
// Do not write int main () function
Return Convert2BST (num, 0, num. size ()-1 );
}
};
Struct TreeNode {
Int val;
TreeNode * left;
TreeNode * right;
TreeNode (int x): val (x), left (NULL), right (NULL ){}
};
Class Solution {
Public:
TreeNode * Convert2BST (vector <int> & num, int start, int end)
{
If (start> end)
Return NULL;
Int mid = (start + end)/2;
TreeNode * pNode = new TreeNode (num [mid]);
PNode-> left = Convert2BST (num, start, mid-1 );
PNode-> right = Convert2BST (num, mid + 1, end );
Return pNode;
}
TreeNode * sortedArrayToBST (vector <int> & num ){
// Start typing your C/C ++ solution below
// Do not write int main () function
Return Convert2BST (num, 0, num. size ()-1 );
}
};