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 002f88c

Browse files
update 590
1 parent d5427fb commit 002f88c

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
public class _590 {
99
public static class Solution1 {
1010
public List<Integer> postorder(Node root) {
11-
List<Integer> result = new ArrayList<>();
12-
if (root == null) {
13-
return result;
14-
}
15-
dfs(root, result);
16-
result.add(root.val);
17-
return result;
11+
return post(root, new ArrayList<>());
1812
}
1913

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

0 commit comments

Comments
(0)

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