-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPreorder.java
More file actions
32 lines (26 loc) · 732 Bytes
/
Preorder.java
File metadata and controls
32 lines (26 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.lga.algorithm.tag.homework.Week_02;
import com.lga.datastruct.lru.Node;
import com.sun.org.apache.xpath.internal.operations.And;
import org.junit.Assert;
import org.junit.Test;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/**
* 589. N叉树的前序遍历
*
* https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/description/
*/
public class Preorder {
List<Integer> ans = new LinkedList<>();
public List<Integer> preorder(Node root) {
while (root != null) {
ans.add(root.val);
for (Node node : root.children) {
preorder(node);
}
}
return ans;
}
}