531. Lonely Pixel I

T: O(mn)

S: O(m+n)

```java
class Solution {
    public int findLonelyPixel(char[][] picture) {
        int m = picture.length;
        int n = picture[0].length;
        int[] rowWCount = new int[m];
        int[] colWCount = new int[n];
        int count = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (picture[i][j] == 'B') {
                    rowWCount[i]++;
                    colWCount[j]++;
                }
            }
        }
        for (int i = 0; i < m; i++) {
            if (rowWCount[i] != 1) {
                continue;
            }
            for (int j = 0; j < n; j++) {
                if (picture[i][j] == 'B' && colWCount[j] == 1) {
                    count++;
                }
            }
        }
        return count;
    }
}
```

Last updated