deno.land / x / masx200_leetcode_test@10.6.5 / add-one-row-to-tree / index.ts
1234567891011121314151617181920212223242526import { 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), );}
Version Info