18ms Fast One Pass C++ Solution
\nclass Solution {\npublic:\n    int help(TreeNode* root, int sum, unordered_map<int, int>& store, int pre) {\n        if (!root) return 0;\n        root->val +
```\nclass Solution {\npublic:\n    int help(TreeNode* root, int sum, unordered_map<int, int>& store, int pre) {\n        if (!root) return 0;\n        root->val += pre;\n        int res = (root->val == sum) + (store.count(root->val - sum) ? store[root->val - sum] : 0);\n        store[root->val]++;\n        res += help(root->left, sum, store, root->val) + help(root->right, sum, store, root->val);\n        store[root->val]--;\n        return res;\n    }\n\n    int pathSum(TreeNode* root, int sum) {\n        unordered_map<int, int> store;\n        return help(root, sum, store, 0);\n    }\n};\n```
[]