[C++] Using 2 one Liner Function || Easy Code Too
\nclass Solution {\npublic:\n    int DFS(TreeNode *root,int sum){\n        return root?(root->val==sum) + DFS(root->left,sum-root->val) + DFS(root->right,sum-ro
```\nclass Solution {\npublic:\n    int DFS(TreeNode *root,int sum){\n        return root?(root->val==sum) + DFS(root->left,sum-root->val) + DFS(root->right,sum-root->val):0;\n    }\n    int pathSum(TreeNode* root, int sum) {\n        return root? DFS(root,sum) + pathSum(root->left,sum) + pathSum(root->right,sum):0;\n    }\n};\n```\n**or Can Try This**\n```Same Concept But Easy To Understand```\n```\nclass Solution {\npublic:\n    int DFS(TreeNode *root,int sum){\n        if(root==nullptr)\n            return 0;\n        int ans = root->val==sum?1:0;\n        return ans + DFS(root->left,sum-root->val) + DFS(root->right,sum-root->val);\n    }\n    int pathSum(TreeNode* root, int sum) {\n        if(root==nullptr)\n            return 0;\n        return DFS(root,sum) + pathSum(root->left,sum) + pathSum(root->right,sum);\n    }\n};\n```
[]