We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 12c8c7c commit e660f34Copy full SHA for e660f34
solution/0129.Sum Root to Leaf Numbers/Solution.java
@@ -0,0 +1,11 @@
1
+class Solution {
2
+ public int sumNumbers(TreeNode root) {
3
+ return sumNumbers(root,0);
4
+ }
5
+ private int sumNumbers(TreeNode root, int sum) {
6
+ if (root==null) return 0;
7
+ sum = sum *10 + root.val;
8
+ if (root.left==null && root.right==null) return sum;
9
+ return sumNumbers(root.left,sum)+sumNumbers(root.right,sum);
10
11
+}
0 commit comments