Leetcode-5017 Sum of Root To Leaf Binary Numbers(从根到叶的二进制数之和)

 1 typedef long long ll;  2 class Solution  3 {  4     public:  5         ll rnt = 0;  6         void go(TreeNode* root,int val)  7  {  8             val = (val*2+root->val)%1000000007;  9             if(root->left==NULL && root->right==NULL) 10  { 11                 rnt = (rnt+val)%1000000007;return ; 12  } 13             if(root->left) 14             go(root->left,val); 15             if(root->right) 16             go(root->right,val); 17  } 18         int sumRootToLeaf(TreeNode* root) 19  { 20             if(!root) return 0; 21             go(root,0); 22             return rnt; 23  } 24 };

没取余WA了两发,气死我了spa

相关文章
相关标签/搜索