-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path531.cpp
More file actions
28 lines (26 loc) · 735 Bytes
/
531.cpp
File metadata and controls
28 lines (26 loc) · 735 Bytes
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
class Solution {
public:
int findLonelyPixel(vector<vector<char>>& picture) {
int m = picture.size();
int n = picture[0].size();
vector<int> rows(m, 0);
vector<int> cols(n, 0);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (picture[i][j] == 'B') {
rows[i]++;
cols[j]++;
}
}
}
int cnt = 0;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (picture[i][j] == 'B') {
if (rows[i] == 1 && cols[j] == 1) cnt++;
}
}
}
return cnt;
}
};