题意以及限制条件
-
题目:
-
限制条件:
想到的所有可能解法
-
Ways_1——递归
- 时间复杂度——O(n);空间复杂度——O(n)。
对应的代码
- Ways_1
class Solution {
private List<Integer> res =new ArrayList<Integer>();
public List<Integer> preorder(Node root) {
//Terminator
if (root == null) return res;
//Current Logic
res.add(root.val);
for (Node node : root.children) {
//Drill Down
preorder(node);
}
return res;
//Restore Current Data
}
}