using Hashmap || c++ || simple
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\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 {\nprivate:\n    void dfs(TreeNode* root, long long targetSum, int& count, unordered_map<long long, int>& mp, long long sum) {\n        if (root == nullptr) {\n            return;\n        }\n        \n        sum += root->val;\n        \n        if (sum == targetSum) {\n            count++;\n        }\n        \n        if (mp.find(sum - targetSum) != mp.end()) {\n            count += mp[sum - targetSum];\n        }\n        \n        mp[sum]++;\n        \n        dfs(root->left, targetSum, count, mp, sum);\n        dfs(root->right, targetSum, count, mp, sum);\n        \n        mp[sum]--;\n    }\n\npublic:\n    int pathSum(TreeNode* root, int targetSum) {\n        int count = 0;\n        unordered_map<long long, int> mp;\n        dfs(root, targetSum, count, mp, 0);\n        return count;\n    }\n};\n\n```
['C++']