1
class Solution {
2
int res;
3

4
public int sumNumbers(TreeNode root) {
5
res = 0;
6
getSum(root, 0);
7

8
return res;
9
}
10

11
public void getSum(TreeNode root, int sum) {
12

13
if (root.left == null && root.right == null) {
14
res += (sum * 10 + root.val);
15
}
16

17
if (root.left != null) getSum(root.left, sum * 10 + root.val);
18

19
if (root.right != null) getSum(root.right, sum * 10 + root.val);
20
}
21
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0