Created
December 31, 2017 11:45
-
-
Save tamlt2704/6a399c5a37f49d7b21e44ea89e08c5b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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