File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,8 @@ go get github.com/masx200/leetcode-test
152
152
153
153
<summary >展开查看</summary >
154
154
155
+ https://leetcode.cn/problems/binary-tree-cameras
156
+
155
157
https://leetcode.cn/problems/snail-traversal/
156
158
157
159
https://leetcode.cn/problems/function-composition
Original file line number Diff line number Diff line change
1
+ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts" ;
2
+
3
+ function minCameraCover ( root : TreeNode | null ) : number {
4
+ const dfs = ( root : TreeNode | null ) : [ number , number , number ] => {
5
+ if ( ! root ) {
6
+ return [ Math . floor ( Number . MAX_SAFE_INTEGER / 2 ) , 0 , 0 ] ;
7
+ }
8
+ const [ la , lb , lc ] = dfs ( root . left ) ;
9
+ const [ ra , rb , rc ] = dfs ( root . right ) ;
10
+ const a = lc + rc + 1 ;
11
+ const b = Math . min ( a , Math . min ( la + rb , ra + lb ) ) ;
12
+ const c = Math . min ( a , lb + rb ) ;
13
+ return [ a , b , c ] ;
14
+ } ;
15
+
16
+ return dfs ( root ) [ 1 ] ;
17
+ }
18
+ export default minCameraCover ;
You can’t perform that action at this time.
0 commit comments