Lonely Pixel I
Input:
[['W', 'W', 'B'],
['W', 'B', 'W'],
['B', 'W', 'W']]
Output:
3
Explanation:
All the three 'B's are black lonely pixels.Last updated
Input:
[['W', 'W', 'B'],
['W', 'B', 'W'],
['B', 'W', 'W']]
Output:
3
Explanation:
All the three 'B's are black lonely pixels.Last updated
class Solution:
def findLonelyPixel(self, picture: List[List[str]]) -> int:
if not picture or not picture[0]:
return 0
n, m = len(picture), len(picture[0])
col = [0]*m
res = 0
for i in range(n):
for j in range(m):
if picture[i][j] == 'B':
col[j] += 1
for i in range(n):
cnt = pos = 0
for j in range(m):
if picture[i][j] == 'B':
cnt += 1
pos = j
if cnt == 1 and col[pos] == 1:
res += 1
return res