/* // Definition for a Node. class Node { public int val; public List<Node> children; public Node() {} public Node(int _val) { val = _val; } public Node(int _val, List<Node> _children) { val = _val; children = _children; } }; */
classSolution { public List<List<Integer>> levelOrder(Node root) { List<List<Integer>> result = newLinkedList<>(); if (root == null) { return result; } Queue<Node> queue = newLinkedList<>(); queue.offer(root); while (!queue.isEmpty()) { List<Integer> nums = newLinkedList<>(); for (inti= queue.size(); i > 0; i--) { Nodenode= queue.poll(); nums.add(node.val); queue.addAll(node.children); } result.add(nums); } return result; } }