deno.land / x / masx200_leetcode_test@10.6.5 / deepest-leaves-sum / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
export default function deepestLeavesSum(root: TreeNode | null): number { if (!root) return 0; let cur = [root];
while (cur.length) { const temp: typeof cur = [];
cur.map((n) => [n.left, n.right].filter(Boolean)).forEach((a) => temp.push(...(a as TreeNode[])) );
if (!temp.length) { return cur.reduce((a, v) => a + v.val, 0); } cur = temp; } return 0;}
masx200_leetcode_test

Version Info

Tagged at
a year ago