deno.land / x / masx200_leetcode_test@10.6.5 / add-one-row-to-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
23
24
25
26
import { TreeNode } from "../mod.ts";
export default function addOneRow( root: TreeNode | null, val: number, depth: number,): TreeNode | null { if (!root || !depth) return null;
if (depth === 1) return new TreeNode(val, root);
if (depth === 2) { return new TreeNode( root.val, new TreeNode(val, root.left), new TreeNode(val, null, root.right), ); }
return new TreeNode( root.val, addOneRow(root.left, val, depth - 1), addOneRow(root.right, val, depth - 1), );}
masx200_leetcode_test

Version Info

Tagged at
a year ago