/**
* 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* new_root ;
void get_subtree(TreeNode* cur, int target)
{
if(cur==nullptr) return;
if(cur->val == target)
{
new_root = cur;
return;
}
get_subtree(cur->left , target) ;
get_subtree(cur->right , target);
}
TreeNode* searchBST(TreeNode* root, int val) {
if(root==nullptr) return nullptr;
get_subtree(root,val);
return new_root;
}
};