interestingqs
BAN USERSimilar approach to guilhebl's solution but without modifying the original image
def lonely_pixel():
def count_lonely_pixels(matrix):
rows,total={},0
for r in xrange(len(matrix)):
cnt,lastpixelcol=0,None
for c in xrange(len(matrix[0])):
if matrix[r][c]==1:
cnt+=1
if cnt>1:
break
lastpixelcol=c
if cnt==1:
rows[r]=lastpixelcol
for c in xrange(len(matrix[0])):
cnt,lastpixelrow=0,None
for r in xrange(len(matrix)):
if matrix[r][c]==1:
cnt+=1
if cnt>1:
break
lastpixelrow=r
if cnt==1 and rows.get(lastpixelrow)==c:
total+=1
return total
matrix=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
print str(count_lonely_pixels(matrix))
lonely_pixel()
binary search recursively:
- interestingqs April 26, 2019