Why we need to pop_back here


#1

void allPaths(TreeNode* A, int B,vector<vector >& paths,vector V)
{
if (A->left == NULL && A->right == NULL && (B)==0)
{
paths.push_back(V);
}

if(A->left != NULL)
   {
        V.push_back(A->left->val);
        allPaths((A->left),(B - A->left->val),paths,V);
        **V.pop_back();**
   }

if(A->right != NULL)
     {
        V.push_back(A->right->val);
        allPaths((A->right),(B - A->right->val),paths,V);
        **V.pop_back();**
 }

}

vector<vector > Solution::pathSum(TreeNode* A, int B) {
vector<vector > paths;
vector checkpaths;
if(A == NULL)
return paths;

checkpaths.push_back(A->val);
allPaths(A,B- A->val,paths,checkpaths);

return paths;

}
this is my solution here I am passing vector V by value but still, I need to write pop_back to get my solution accepted can anyone explain me why this is the case