Python 240ms simple


  • 1
    class Solution(object):
        def findBlackPixel(self, picture, N):
            """
            :type picture: List[List[str]]
            :type N: int
            :rtype: int
            """
            r_no = len(picture)
            c_no = len(picture[0])
            search_r = [i for i in range(r_no) if picture[i].count('B')==N]
            search_c = [i for i in range(c_no) if [j[i] for j in picture].count('B')==N]
            count = 0
            for r in search_r:
                for c in search_c:
                    if picture[r][c] == 'B':
                        cur_row = picture[r]
                        sibs = filter(lambda x:x[c]=='B', picture)
                        if all([s==cur_row for s in sibs]):
                            count += 1
            return count
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.