forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
35 lines (35 loc) · 870 Bytes
/
Solution.cpp
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
29
30
31
32
33
34
35
class Solution {
public:
int findLonelyPixel(vector<vector<char>>& picture) {
int m = picture.size(), n = picture[0].size();
vector<int> rows(m);
vector<int> cols(n);
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
if (picture[i][j] == 'B')
{
++rows[i];
++cols[j];
}
}
}
int res = 0;
for (int i = 0; i < m; ++i)
{
if (rows[i] == 1)
{
for (int j = 0; j < n; ++j)
{
if (picture[i][j] == 'B' && cols[j] == 1)
{
++res;
break;
}
}
}
}
return res;
}
};