GFG Approach C++


#1
bool search(TreeNode *A,int B,vector<int> &ans)
{
    if(A==NULL)
        return false;
    ans.push_back(A->val);
    if(A->val==B)
        return true;

    if(search(A->left,B,ans) || search(A->right,B,ans) )
        return true;
    ans.pop_back();
    return false;
}
vector<int> Solution::solve(TreeNode* A, int B) {
    vector<int> ans;
    search(A,B,ans);
    return ans;
}