Skip to content

Instantly share code, notes, and snippets.

@tamlt2704
Created December 31, 2017 11:45
Show Gist options
  • Select an option

  • Save tamlt2704/6a399c5a37f49d7b21e44ea89e08c5b1 to your computer and use it in GitHub Desktop.

Select an option

Save tamlt2704/6a399c5a37f49d7b21e44ea89e08c5b1 to your computer and use it in GitHub Desktop.
# https://leetcode.com/problems/max-area-of-island/description/
# complex number make things simplers
class Solution(object):
def maxAreaOfIsland(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
grid = {i + j*1j: val for i, row in enumerate(grid) for j, val in enumerate(row)}
def area(z):
return grid.pop(z, 0) and 1 + sum(area(z + 1j**k) for k in range(4))
return max(map(area, set(grid)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment