C++ | | Easy Understanding | | Similar to K-Sum Pair
Approach\n Describe your approach to solving the problem. \n\n\n\n# Code\n\nclass Solution {\npublic:\n    void solve(TreeNode* root,vector<int> v,int &ct,int k
# Approach\n<!-- Describe your approach to solving the problem. -->\n![WhatsApp Image 2023-07-10 at 11.20.21 PM.jpeg](https://assets.leetcode.com/users/images/d41a887c-62d4-4b6d-ba4c-12bc3588ea7f_1689011450.127706.jpeg)\n\n\n# Code\n```\nclass Solution {\npublic:\n    void solve(TreeNode* root,vector<int> v,int &ct,int k){\n        if(root == NULL) return ;\n        v.push_back(root->val);\n\n        solve(root->left,v,ct,k);\n        solve(root->right,v,ct,k);\n\n        int n = v.size();\n        long long sum = 0;\n\n        for(int i = n - 1;i >= 0;--i){\n            sum += v[i];\n            if(sum == k)\n                ct++;\n        }\n        v.pop_back();\n    }\n    int pathSum(TreeNode* root, int k) {\n        vector<int> v;\n        int ct = 0;\n        solve(root,v,ct,k);\n        return ct;\n    }\n};\n```
['C++']