C++ Simple Recursion
\nclass Solution {\npublic:\n    void dfs(TreeNode* root,int sum,int cur,int &ans){\n        if(root){\n            cur+=root->val;\n            if(cur==sum){\n
```\nclass Solution {\npublic:\n    void dfs(TreeNode* root,int sum,int cur,int &ans){\n        if(root){\n            cur+=root->val;\n            if(cur==sum){\n                ans++;\n            }\n            dfs(root->left,sum,cur,ans);\n            dfs(root->right,sum,cur,ans);\n        }\n    }\n    \n    void fromNode(TreeNode *root,int sum,int &ans){\n        if(root){\n            dfs(root,sum,0,ans);\n            fromNode(root->left,sum,ans);\n            fromNode(root->right,sum,ans);\n        }        \n    }\n    \n    int pathSum(TreeNode* root, int sum) {\n        int ans=0;\n        fromNode(root,sum,ans);\n        return ans;\n    }\n};\n```
[]