Mainly I group and count equal rows. Look for rows that appear N times and that have N black pixels. If you find one, add N for each of its black columns that doesn't have extra black pixels (in other rows).
def findBlackPixel(self, picture, N): ctr = collections.Counter(map(tuple, picture)) cols = [col.count('B') for col in zip(*picture)] return sum(N * zip(row, cols).count(('B', N)) for row, count in ctr.items() if count == N == row.count('B'))
I came up with some ideas based on your amazing solution in Pixel I. Just attached my solution in discussion. Thanks for your help!
why the except is 9 not 13?
Maybe you forgot the second requirement which is
"2. For all rows that have a black pixel at column C, they should be exactly the same as row R". For the input you mentioned, only 3
"BWBWWB" are "valid" to be consider for answer, so yes, it is 9 instead of 13.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.