8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 237bd62 commit 0c1786aCopy full SHA for 0c1786a
leetcode/968.监控二叉树/minCameraCover.go
@@ -0,0 +1,49 @@
1
+package _68_监控二叉树
2
+
3
+/**
4
+ * Definition for a binary tree node.
5
+ * type TreeNode struct {
6
+ * Val int
7
+ * Left *TreeNode
8
+ * Right *TreeNode
9
+ * }
10
+ */
11
12
+type TreeNode struct {
13
+ Val int
14
+ Left *TreeNode
15
+ Right *TreeNode
16
+}
17
18
+func minCameraCover(root *TreeNode) int {
19
+ var fn func(root *TreeNode) int
20
+ var result int
21
+ fn = func(root *TreeNode) int {
22
+ if root == nil {
23
+ return 2
24
+ }
25
+ left := fn(root.Left)
26
+ right := fn(root.Right)
27
28
+ if left == 2 && right == 2 {
29
+ return 0
30
31
32
+ if left == 0 || right == 0 {
33
+ result++
34
+ return 1
35
36
37
+ if left == 1 || right == 1 {
38
39
40
41
+ return -1
42
43
44
+ if fn(root) == 0 {
45
46
47
48
+ return result
49
0 commit comments