Last updated 2 years ago
My Solution:
class Solution { List<Integer> res = new ArrayList<>(); public List<Integer> preorder(Node root) { in(root); return res; } private void in(Node root){ if(root == null) return; res.add(root.val); for (Node n: root.children){ in(n); } } }