File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
1010
1111##### 包含的内容如下
1212
13+ https://leetcode.cn/problems/deepest-leaves-sum/
14+
1315https://leetcode.cn/problems/decode-ways
1416
1517https://leetcode.cn/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/
Original file line number Diff line number Diff line change 1+ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts" ;
2+
3+ export default function deepestLeavesSum ( root : TreeNode | null ) : number {
4+ if ( ! root ) return 0 ;
5+ let cur = [ root ] ;
6+
7+ while ( cur . length ) {
8+ const temp : typeof cur = [ ] ;
9+
10+ cur . map ( ( n ) => [ n . left , n . right ] . filter ( Boolean ) ) . forEach ( ( a ) =>
11+ temp . push ( ...( a as TreeNode [ ] ) )
12+ ) ;
13+
14+ if ( ! temp . length ) {
15+ return cur . reduce ( ( a , v ) => a + v . val , 0 ) ;
16+ }
17+ cur = temp ;
18+ }
19+ return 0 ;
20+ }
You can’t perform that action at this time.
0 commit comments