Skip to content

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 void dfs(Node root, List<Integer> result) {
14+
private List<Integer> post(Node root, List<Integer> list) {
2115
if (root == null) {
22-
return;
16+
return list;
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy