deno.land / x / masx200_leetcode_test@10.6.5 / n-ary-tree-postorder-traversal / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Node } from "../n-ary-tree-level-order-traversal/Node.ts";
export default function postorder(root: Node | null): number[] { if (!root) { return []; } const res: number[] = []; posthelper(root, (a) => res.push(a)); return res;}function posthelper(root: Node | null, output: (a: number) => void) { if (!root) { return; }
for (const n of root.children) { posthelper(n, output); } output(root.val); // root.children.forEach(n=>{ // prehelper(n, output); // })}
masx200_leetcode_test

Version Info

Tagged at
a year ago