100% BEATS  cpp/c++  || TC=O(N) || USE HASHMAP || EASY CODE.
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 {\n\n    // private: int total=0;\n    // private: int count=0;\n    // private:\n    // void dfs(TreeNode* root,int k,int sum){\n    //     if(root==NULL){\n    //         return;\n    //     }\n    //     sum+=root->val;\n    //     if(sum==k){\n    //         count++;\n    //     }\n    //     dfs(root->left,k,sum);\n    //     dfs(root->right,k,sum);\n    // }\n// private:\n//     void solve(TreeNode* root, int k,int sum,HashMap<int,int>hm){\n//         if(root==NULL){\n//             return;\n//         }\n//         sum+=root->val;\n//         if(hm.containskey(sum-k)){\n//             total+=hm.get(sum-k);\n//         }\n//         hm.put(sum,getOrDefault(sum,0)+1);\n//         solve(root->left,k,sum,hm);\n//         solve(root->right,k,sum,hm);\n//         hm.put(sum,hm.get(sum)-1);\n//         return;\n//     }\npublic:\n    #define ll long long\n    map<ll ,int> mp;\n    int ans=0;\n    void solve(TreeNode* root, int targetSum,ll currSum){\n        if(root==NULL) return;\n        currSum+=root->val;\n        ans+=mp[currSum-targetSum];//it mean between the ongoing process there is a place where targetSum is generated.\n        mp[currSum]++;\n        solve(root->left , targetSum,currSum);\n        solve(root->right , targetSum,currSum);\n        mp[currSum]--;\n        currSum-=root->val;\n\n    }\n    int pathSum(TreeNode* root, int k) {\n        // TIME COMPLEXITY ORDER OF (N*2).\n        // if(root==NULL){\n        //     return 0;\n        // }\n        // // int count=0;\n        // dfs(root,k,0);\n        // pathSum(root->left,k);\n        // pathSum(root->right,k);\n        // return count;\n        // TIME COMPLEXITY ORDER OF (N).\n        // if(root==NULL){\n        //     return 0;\n        // }\n        // HashMap<int,int>hm=new HashMap<>();\n        // hm.put(0,1);\n        // solve(root,k,0,hm);\n        // return total;\n        // ALTERNATIVE SOLUTION.(O(N)) TIME.\n         mp[0]++;\n        ll currSum=0;\n        solve(root,k,currSum);\n        return ans;\n\n    }\n};\n```
['C++']