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 ff3605a commit cd29a91Copy full SHA for cd29a91
problems/0968.监控二叉树.md
@@ -346,8 +346,27 @@ class Solution {
346
347
348
Python:
349
-
350
+```python
+class Solution:
351
+ def minCameraCover(self, root: TreeNode) -> int:
352
+ result = 0
353
+ def traversal(cur):
354
+ nonlocal result
355
+ if not cur:
356
+ return 2
357
+ left = traversal(cur.left)
358
+ right = traversal(cur.right)
359
+ if left == 2 and right == 2:
360
+ return 0
361
+ elif left == 0 or right == 0:
362
+ result += 1
363
+ return 1
364
+ elif left == 1 or right == 1:
365
366
+ else: return -1
367
+ if traversal(root) == 0: result += 1
368
+ return result
369
+```
370
Go:
371
372
0 commit comments