✅Easy solution || ✅Short & Simple || ✅Best Method || ✅Easy-To-Understand
\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(
\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    unordered_map<long, int> mp;\n    void dfs(TreeNode* root, int target, long sum)\n    {\n        if(root)\n        {\n            sum+=root->val;\n            if(mp.find(sum-target)!=mp.end())\n                ans+=mp[sum-target];\n            mp[sum]++;\n            dfs(root->left, target, sum);\n            dfs(root->right, target, sum);\n            mp[sum]--;\n        }\n    }\n    int pathSum(TreeNode* root, int targetSum) {\n        ans=0;\n        mp[0]=1;\n        dfs(root, targetSum, 0);\n        return ans;\n    }\n};\n```\nPlease **UPVOTE** if it helps \u2764\uFE0F\uD83D\uDE0A\nThank You and Happy To Help You!!
['C++']