Three Aproach 1. Brute Force 2. Vector Method 3. Hash Map Method
Brute Force approch\n\nclass Solution \n{ \npublic: \n    int PathSum2(TreeNode* node, long long sum) \n    { \n        if (node == NULL) \n            return 0
Brute Force approch\n```\nclass Solution \n{ \npublic: \n    int PathSum2(TreeNode* node, long long sum) \n    { \n        if (node == NULL) \n            return 0; \n        int count = 0; \n        if (node->val == sum) \n            count = 1; \n        long long newSum = sum - node->val; \n        count += PathSum2(node->left, newSum); \n        count += PathSum2(node->right, newSum); \n        return count; \n    } \n    int pathSum(TreeNode* root, int sum) //main function \n    { \n        if (root == NULL) \n            return 0; \n        return pathSum(root->left, sum) +  \n                pathSum(root->right, sum) + \n                  PathSum2(root, sum); //check for every node\n    } \n};\n```\nVector method\n```\nclass Solution { \npublic: \n    int count=0; \n    vector<int>v; \n    int pathSum(TreeNode* root, int targetSum) { \n        sol(root,targetSum); \n        return count; \n    } \n    void sol(TreeNode* root,int sum){ \n        if(root==NULL){ \n            return; \n        } \n        v.push_back(root->val); \n        sol(root->left,sum); \n        sol(root->right,sum); \n        long long temp=0; \n        for(int i=v.size()-1;i>=0;i--){ \n            temp+=v[i]; \n            if(temp==sum){ \n                count++; \n            } \n        } \n        v.pop_back(); \n    } \n};\n```\nHash Map approach\n```\nclass Solution {\npublic:\n    int total =0;\n    int pathSum(TreeNode* root, int targetsum) {\n        if(!root)return 0;\n        unordered_map<long long ,int>map;\n        sol(root,0,targetsum,map);\n        return total;\n    }\n    void sol(TreeNode* root, long long sum ,int targetsum,unordered_map<long long ,int>map){\n        if(!root)return;\n        sum=sum+root->val;\n        if(sum==targetsum)total++;\n        if(map.find(sum-targetsum)!=map.end()){\n            total=total+map[sum-targetsum];\n        }\n        map[sum]++;\n        sol(root->left,sum,targetsum,map);\n        sol(root->right,sum,targetsum,map);\n        map[sum]--;\n    }\n};\n```
['C++']