Simple Python Solution beats 90%


  • 0
    C
    T = 0
    N = 0
    for i in range(len(grid)): 
        for j in range(len(grid[0])): 
             if grid[i][j]==1:
                T+=1
                try:
                    if grid[i][j+1]==1:
                       N+=1
                except:
                       pass
                try:
                    if grid[i+1][j]==1:
                       N+=1
                except:
                      pass
    return T*4-2*N
    

Log in to reply
 

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