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