Easiest CPP code....backtracking used....have a look


#1

void find(TreeNode* p,vector<vector> &v,vector &empty,int curr,int target)
{
if(p==NULL)
return;

curr+=p->val;
empty.push_back(p->val);
if(p->left==NULL && p->right==NULL)
{
    if(curr==target)
    {v.push_back(empty);}
    
    empty.pop_back();
    return;
}

find(p->left,v,empty,curr,target);
find(p->right,v,empty,curr,target);
empty.pop_back();

}
vector<vector > Solution::pathSum(TreeNode* A, int B) {
vector<vector> v;
vector empty;
find(A,v,empty,0,B);
return v;
}