Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 962f928

Browse files
committed
update 1022.sum-of-root-to-leaf-binary-numbers.java
1 parent 2eb27c7 commit 962f928

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

‎1022.sum-of-root-to-leaf-binary-numbers.java‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,21 @@
5858
* }
5959
*/
6060
class Solution {
61-
int callme(int cur, TreeNode root){
61+
int ans = 0;
62+
void callme(int cur, TreeNode root){
6263
if(root == null)
63-
return0;
64+
return;
6465
cur = cur*2 + root.val;
65-
if(root.left == null && root.right == null)
66-
return cur;
67-
return callme(cur, root.left) + callme(cur, root.right);
66+
if(root.left == null && root.right == null){
67+
ans += cur;
68+
return;
69+
}
70+
callme(cur, root.left);
71+
callme(cur, root.right);
6872
}
6973
public int sumRootToLeaf(TreeNode root) {
70-
return callme(0, root);
74+
callme(0, root);
75+
return ans;
7176
}
7277
}
7378
// @lc code=end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /