SplitBST
It's a premium problem. So it's not tested;
Solution:
vector<TreeNode*> SplitBST(TreeNode* root, int V)
{
vector<TreeNode*> ans (2, nullptr)
if(root == nullptr) return ans;
int x = root->val > V ? 1 : 0;
int y = root->val > V ? 0 : 1;
auto& node = root->val > V ? root->left : root->right;
ans[x] = root;
auto t = SplitBST(node, V);
node = t[x];
ans[y] = t[y];
return ans;
}
No comments:
Post a Comment