Simple compact C++|
Intuition\n Describe your first thoughts on how to solve this problem. \nCheck for left and right subtree and keep decrementing target sum\nand if root->data eq
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCheck for left and right subtree and keep decrementing target sum\nand if root->data equal to target sum then c++.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nDo recursive call for all the nodes and check how many times target sum will occur . \n - Note : take sum as long long to avoid integer overflow\n\n# Complexity\n- Time complexity:O(N^2) in wrost\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n\nclass Solution {\npublic:\nint c=0;\n  \n   void getPath(TreeNode * root ,long long int sum){\n       if(!root)return ;\n      if(root->val==sum)c++;\n      getPath(root->left,sum-root->val);\n      getPath(root->right,sum-root->val);\n     \n   }\n    int pathSum(TreeNode* root, int t) {\n      if(!root)return 0;\n      getPath(root,(long long)t);\n      pathSum(root->left,t);\n      pathSum(root->right,t);\n      return c;\n    }\n};\n```
['Tree', 'C++']