LC: 531. Lonely Pixel I
https://leetcode.com/problems/lonely-pixel-i/
Given an m x n picture consisting of black 'B' and white 'W' pixels, return the number of black lonely pixels.
A black lonely pixel is a character 'B' that located at a specific position where the same row and same column don't have any other black pixels.
Example 1:![]()
Input: picture = [["W","W","B"],["W","B","W"],["B","W","W"]]
Output: 3
Explanation: All the three 'B's are black lonely pixels.Example 2:![]()
Input: picture = [["B","B","B"],["B","B","W"],["B","B","B"]]
Output: 0Constraints:
m == picture.lengthn == picture[i].length1 <= m, n <= 500picture[i][j]is'W'or'B'.
The Essence:
Man kann einfach die Definition des “lonely” Pixels verwenden und die Anzahl der schwarzen Pixels in allen Zeilen und Spalten abzählen. In einer zweiten Schleife kann man diese Anzahlen vergleichen, um zu finden, welche Pixels “lonely” sind.
Details:
Für das Zählen braucht man 2 Arrays. Außerdem muss man beachten, dass ein “lonely” Pixel schwarz ist.
Solution: https://github.com/spiralgo/algorithms/blob/master/src/main/java/algorithms/curated170/medium/LonelyPixel1.java Default Code:
class Solution {
public int findLonelyPixel(char[][] picture) {
}
}Last updated