blob: c73650b778c4182adc05486d1ab23a12188a6243 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include "leetcode.h"
class Solution {
public:
int ans;
int minCameraCover(TreeNode *root) {
if (helper(root) == 0)
ans++;
return ans;
}
private:
int helper(TreeNode *root) {
if (!root)
return 1;
int l = helper(root->left);
int r = helper(root->right);
if (l == 0 || r == 0) {
ans++;
return 2;
} else if (l == 2 || r == 2)
return 1;
else
return 0;
}
};
int main() {}
|