forked from kaidul/LeetCode_problems_solution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lonely_Pixel_I.cpp
37 lines (37 loc) · 1.18 KB
/
Lonely_Pixel_I.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
36
37
class Solution {
public:
int findLonelyPixel(vector<vector<char>>& picture) {
int result = 0;
int n = (int)picture.size();
int m = (int)picture[0].size();
vector<bool> col(m, true);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(col[j]) {
if(picture[i][j] == 'B') {
int k = 0;
for(k = 0; k < n; k++) {
if(k != i and picture[k][j] != 'W') {
break;
}
}
if(k == n) {
k = 0;
for(k = j + 1; k < m; k++) {
if(picture[i][k] != 'W') {
break;
}
}
}
if(k == m) {
result++;
}
col[j] = false;
break;
}
}
}
}
return result;
}
};