class Solution {
public:
int findLonelyPixel(vector<vector<char>>& picture) {
int m = picture.size(); //行数
int 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++) { //遍历每行
for (int j = 0; j < n && rows[i] > 0; j++) { //小trick,只遍历rows[i] > 0的列
if (picture[i][j] == 'B' && rows[i] == 1 && cols[j] == 1) res++;
}
}
return res;
}
};