Movatterモバイル変換


[0]ホーム

URL:


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

Commitb0b76d4

Browse files
edit 129
1 parent562db9a commitb0b76d4

File tree

1 file changed

+9
-17
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+9
-17
lines changed

‎src/main/java/com/fishercoder/solutions/_129.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,16 @@ private void dfs(TreeNode root, StringBuilder sb, List<Integer> allNumbers) {
4848
sb.deleteCharAt(sb.length()-1);
4949
}
5050

51-
publicstaticvoidmain(String...strings) {
52-
more_concise_versiontest =newmore_concise_version();
53-
TreeNoderoot =newTreeNode(1);
54-
root.left =newTreeNode(2);
55-
root.right =newTreeNode(3);
56-
System.out.println(test.sumNumbers(root));
57-
}
58-
}
51+
classmore_concise_version {
52+
publicintsumNumbers(TreeNoderoot) {
53+
returndfs(root,0);
54+
}
5955

60-
classmore_concise_version{
61-
publicintsumNumbers(TreeNoderoot) {
62-
returndfs(root,0);
56+
privateintdfs(TreeNoderoot,intsum) {
57+
if (root ==null)return0;
58+
if (root.left ==null &&root.right ==null)returnsum *10 +root.val;
59+
returndfs(root.left,sum *10 +root.val) +dfs(root.right,sum *10 +root.val);
60+
}
6361
}
6462

65-
privateintdfs(TreeNoderoot,intsum) {
66-
if(root ==null)return0;
67-
if(root.left ==null &&root.right ==null)returnsum*10+root.val;
68-
returndfs(root.left,sum*10+root.val) +dfs(root.right,sum*10+root.val);
69-
}
7063
}
71-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp