Very small Python


  • 1

    There's an edge if you can find two adjacent cells of different color.

    def islandPerimeter(self, A):
        R, C = len(A), len(A[0])
        def get(r, c):
            return A[r][c] if 0 <= r < R and 0 <= c < C else 0
            
        return sum( ( get(r,c) ^ get(r-1,c) ) + ( get(r,c) ^ get(r,c-1) )
                    for r in xrange(R+1) for c in xrange(C+1) )
    

Log in to reply
 

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