✅Easy Simple and Crisp Solution || CPP code with commented Explanation
\u2B06\uFE0F UPVOTE \u2B06\uFE0F\nThe Simple catch in the question is that we need to take each node as a root and traverse from that node till the end(leaf nod
**\u2B06\uFE0F UPVOTE \u2B06\uFE0F**\nThe Simple catch in the question is that we need to take each node as a root and traverse from that node till the end(leaf node), if at any node we see the current sum == target Sum, we increament the answer......else we keep traversal going on on the left and right sub-trees.\n\nBelow is the Full Code :\n```\nclass Solution {\npublic:\n    int ans=0;\n    void solve(TreeNode* root,int sum,long long &curr)\n    {\n        if(!root)return;\n        curr=(curr+root->val);  \n        if(curr==sum)ans++;     //if(curr==targetSum, increament ans)\n        solve(root->left,sum,curr);  //recur for left subtree\n        solve(root->right,sum,curr);   //recur for right subtree\n        curr-=root->val;     //Backtracking \n    }\n    \n    int pathSum(TreeNode* root, int targetSum) {\n        \n        \n        if(!root)return 0;\n        long long curr=0;\n        solve(root,targetSum,curr);\n        pathSum(root->left,targetSum);  //taking left child as root and calling pathSum function\n        pathSum(root->right,targetSum);  ////taking left child as root and calling pathSum function\n        return ans;\n    }\n};\n```\n***Please, please do \u2B06\uFE0F upvote \u2B06\uFE0F if you found it helpful, it keeps me motivated to post more of such solutions :) and feel free to ask in comments if you have any queries/doubts :)***\n
['Backtracking', 'Depth-First Search', 'Recursion', 'C', 'C++']