C++ solution || Recusrsion with one variable only
\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0)
```\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    void travel(TreeNode* root, int sum)\n    {\n        if(root == NULL)\n            return;\n        if(root->val == sum)\n            ans++;\n        travel(root->left, sum-root->val);\n        travel(root->right, sum-root->val);\n    }\n    \n    int pathSum(TreeNode* root, int sum) {\n        if(root == NULL)\n            return 0;\n        travel(root, sum);\n        pathSum(root->left, sum);\n        pathSum(root->right, sum);\n        return ans;   \n    }\n};\n```
['Recursion', 'C']