-
589. N-ary Tree Preorder Traversal javaLeetCode_Study_Plan/Programming Skills 2022. 9. 20. 17:51
class Solution { public List<Integer> preorder(Node root) { List<Integer> ret = new ArrayList<Integer>(); traverse(root, ret); return ret; } public void traverse(Node root, List<Integer> ret){ if (root==null) return; ret.add(root.val); for (Node child: root.children){ traverse(child, ret); } } }
'LeetCode_Study_Plan > Programming Skills' 카테고리의 다른 글
1232. Check If It Is a Straight Line java (1) 2022.09.20 496. Next Greater Element I java (0) 2022.09.20 1790. Check if One String Swap Can Make Strings Equal java (0) 2022.09.20 202. Happy Number java (0) 2022.09.20 1502. Can Make Arithmetic Progression From Sequence java (0) 2022.09.19