My python AC solution O(mn)


  • 0
    S
            if not picture:
                return 0
            
            count = 0
            for row in picture:
                if row.count('B') == 1:  # if each row has lonely 'B'
                    count += 1
            
            for col in zip(*picture):
                if col.count('B') > 1: # if coulmn has some 'B' not alone
                    count -= col.count('B') # remove them from count
            
            return count if count > 0 else 0
    

Log in to reply
 

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