public List<Integer> levelorder(Node root) {
LinkedList<Node> input = new LinkedList<>();
LinkedList<Integer> output = new LinkedList<>();
if (root == null) {
return output;
}
input.add(root);
while (!input.isEmpty()) {
Node node = input.pop();
output.add(node.val);
if (node.children != null) {
for (Node item : node.children) {
input.add(item);
}
}
}
return output;
}