---
# System prepended metadata

title: 0531. Lonely Pixel I
tags: [Leetcode, Medium]

---

# 0531. Lonely Pixel I
###### tags: `Leetcode` `Medium`
Link: https://leetcode.com/problems/lonely-pixel-i/description/
## 思路
记录每一行每一列有多少B
之后遍历整个picture 看每个B所在的行和列是不是都只有一个B
## Code
```java=
class Solution {
    public int findLonelyPixel(char[][] picture) {
        int m = picture.length, n = picture[0].length;
        int[] rowCount = new int[m];
        int[] colCount = new int[n];
        for(int i=0; i<m; i++){
            for(int j=0; j<n; j++){
                if(picture[i][j]=='B'){
                    rowCount[i]++;
                    colCount[j]++;
                }
            }
        }
        int count = 0;
        for(int i=0; i<m; i++){
            for(int j=0; j<n; j++){
                if(picture[i][j]=='B' && rowCount[i]==1 && colCount[j]==1) count++;
            }
        }
        return count;
    }
}
```