[C++] | Faster | gp_hash_table solution
\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nclass Solution {\npublic:\n    \n    int recurse(TreeNode* root,int sum,int target,gp_h
```\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nclass Solution {\npublic:\n    \n    int recurse(TreeNode* root,int sum,int target,gp_hash_table<int,int>& mp){\n        if(root==NULL)\n            return 0;\n        int ans = 0;\n        sum+=root->val;\n        if(mp.find(sum-target)!=mp.end())\n            ans+=mp[sum-target];\n        mp[sum]++;\n        ans+=recurse(root->left,sum,target,mp);\n        ans+=recurse(root->right,sum,target,mp);\n        if(--mp[sum]==0)\n            mp.erase(sum);\n        return ans;\n    }\n    \n    int pathSum(TreeNode* root, int targetSum) {\n        gp_hash_table<int,int> mp;\n        mp[0]++;\n        return recurse(root,0,targetSum,mp);\n    }\n};\n```
[]