Python O(mn) time and O(m+n) space solution using 2 hash


  • -1
    C

    '''
    rtype = 0
    colIdx = {}
    rowIdx = {}
    for i in range(len(picture)):
    inrow = 0
    for j in range(len(picture[i])):
    if picture[i][j] == 'B':
    inrow += 1
    inrowidx = j
    colIdx[j] = colIdx.get(j,0) + 1
    if inrow==1:
    rowIdx[inrowidx] = 1
    for key,val in colIdx.iteritems():
    if val == 1 and rowIdx.get(key)==1:
    rtype += 1
    return rtype
    '''


Log in to reply
 

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