/
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
/
int wpl;
int n=0;
class Solution {
public:
int Sum(TreeNode root,int n) {
if(root->left==NULL&&root->right==NULL)
{
wpl+=root->valn;
}
if(root->left!=NULL)
Sum(root->left,n+1);
if(root->right!=NULL)
Sum(root->right,n+1);
return wpl;
}
int pathSum(TreeNode root)
{
return Sum(root,0);
}
};