mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Update 0968.监控二叉树,添加C#
This commit is contained in:
@ -726,6 +726,31 @@ impl Solution {
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
### C#
|
||||
```csharp
|
||||
public class Solution
|
||||
{
|
||||
public int res = 0;
|
||||
public int MinCameraCover(TreeNode root)
|
||||
{
|
||||
if (Traversal(root) == 0) res++;
|
||||
return res;
|
||||
}
|
||||
public int Traversal(TreeNode cur)
|
||||
{
|
||||
if (cur == null) return 2;
|
||||
int left = Traversal(cur.left);
|
||||
int right = Traversal(cur.right);
|
||||
if (left == 2 && right == 2) return 0;
|
||||
else if (left == 0 || right == 0)
|
||||
{
|
||||
res++;
|
||||
return 1;
|
||||
}
|
||||
else return 2;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<p align="center">
|
||||
|
Reference in New Issue
Block a user