Update 0968.监控二叉树,添加C#

This commit is contained in:
eeee0717
2024-01-10 10:02:48 +08:00
parent 6b38053a63
commit f292cbaf2e

View File

@ -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">