deno.land / x / masx200_leetcode_test@10.6.5 / binary-tree-paths / 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 { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
export default function binaryTreePaths(root: TreeNode | null): string[] { const res: string[] = []; if (!root) { return res; } const path: number[] = []; dfs(root, res, path); return res;}function dfs(root: TreeNode, res: string[], path: number[]) { path.push(root.val); if (!root.left && !root.right) { res.push(path.join("->")); return; }
for (const node of [root.left, root.right].filter(Boolean) as TreeNode[]) { dfs(node, res, path); path.pop(); }}
masx200_leetcode_test

Version Info

Tagged at
a year ago