N-ary Tree Preorder Traversal LeetCode solution in Python
1function preorder(root: Node | null): number[] {2const res: number[] = [];34const getNodeVal = (node: Node | null): void => {5if (node) {6res.push(node.val);78for (let i = 0; i < node.children.length; i++) {9getNodeVal(node.children[i]);10}11}12};1314getNodeVal(root);1516return res;17}18