-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathLonelyPixelI.cpp
44 lines (37 loc) · 1.06 KB
/
LonelyPixelI.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
38
39
40
41
42
43
44
class Solution {
public:
int findLonelyPixel(vector<vector<char>>& picture) {
int rows = picture.size(), ans = 0;
if(rows == 0){
return ans;
}
int cols = picture[0].size();
map<int, int> forRow, forCol;
for(int i = 0; i < rows; i++){
int count = 0;
for(int j = 0; j < cols; j++){
if(picture[i][j] == 'B'){
count++;
}
}
forRow[i] = count;
}
for(int j = 0; j < cols; j++){
int count = 0;
for(int i = 0; i < rows; i++){
if(picture[i][j] == 'B'){
count++;
}
}
forCol[j] = count;
}
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(picture[i][j] == 'B' && forRow[i] == 1 && forCol[j] == 1){
ans++;
}
}
}
return ans;
}
};