Intitutive C++ solution
\n\n# Approach\n Describe your approach to solving the problem. just run dfs on the tree and at every node assume it to be as root node and calculate number of 
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->just run dfs on the tree and at every node assume it to be as root node and calculate number of path which has sum equal to targetsum using helper function.\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n   int ans=0;\n   int helper(TreeNode* root, int targetSum,long long curr)\n   {\n       if(root==NULL) return 0;\n       curr=curr+root->val;\n       if(curr==targetSum)\n       {\n           return 1+helper(root->left,targetSum,curr)+helper(root->right,targetSum,curr);\n       }\n       return helper(root->left,targetSum,curr)+helper(root->right,targetSum,curr);\n   }\n\nvoid dfs(TreeNode* root, int targetSum)\n{\n   if(root==NULL) return;\n       ans=ans+helper(root,targetSum,0);\n       pathSum(root->left,targetSum);\n       pathSum(root->right,targetSum);\n}\n\n\n    int pathSum(TreeNode* root, int targetSum) {\n        if(root==NULL) return 0;\n        dfs(root,targetSum);\n        return ans;\n      \n        \n    }\n};\n```
['C++']