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

Commit002f88c

Browse files
update 590
1 parentd5427fb commit002f88c

File tree

1 file changed

+7
-14
lines changed
  • src/main/java/com/fishercoder/solutions/firstthousand

1 file changed

+7
-14
lines changed

‎src/main/java/com/fishercoder/solutions/firstthousand/_590.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,18 @@
88
publicclass_590 {
99
publicstaticclassSolution1 {
1010
publicList<Integer>postorder(Noderoot) {
11-
List<Integer>result =newArrayList<>();
12-
if (root ==null) {
13-
returnresult;
14-
}
15-
dfs(root,result);
16-
result.add(root.val);
17-
returnresult;
11+
returnpost(root,newArrayList<>());
1812
}
1913

20-
privatevoiddfs(Noderoot,List<Integer>result) {
14+
privateList<Integer>post(Noderoot,List<Integer>list) {
2115
if (root ==null) {
22-
return;
16+
returnlist;
2317
}
24-
if (root.children.size() >0) {
25-
for (Nodechild :root.children) {
26-
dfs(child,result);
27-
result.add(child.val);
28-
}
18+
for (Nodechild :root.children) {
19+
post(child,list);
2920
}
21+
list.add(root.val);
22+
returnlist;
3023
}
3124
}
3225
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp