deno.land / x / masx200_leetcode_test@10.6.5 / construct-string-from-binary-tree / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
export default function tree2str(root: TreeNode | null): string { if (!root) { return ""; } if (!root.left && !root.right) { return String(root.val); } if (!root.right) { return String(root.val) + "(" + tree2str(root.left) + ")"; } return ( String(root.val) + "(" + tree2str(root.left) + ")(" + tree2str(root.right) + ")" );}
masx200_leetcode_test

Version Info

Tagged at
a year ago