deno.land / x / masx200_leetcode_test@10.6.5 / smallest-subtree-with-all-the-deepest-nodes / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";import maxDepth from "../maximum-depth-of-binary-tree/index.ts";
export default function subtreeWithAllDeepest( root: TreeNode | null,): TreeNode | null { if (root == null) { return null; }
const left = maxDepth(root.left); const right = maxDepth(root.right); if (left === right) return root; if (left < right) return subtreeWithAllDeepest(root.right); return subtreeWithAllDeepest(root.left);}
masx200_leetcode_test

Version Info

Tagged at
a year ago