@@ -0,0 +1,1702 @@
+# Time:  O(m * n)%0A# Space: O(1)%0A%0A# Given a non-empty 2D array grid of 0's and 1's,%0A# an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.)%0A# You may assume all four edges of the grid are surrounded by water.%0A#%0A# Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.)%0A#%0A# Example 1:%0A# %5B%5B0,0,1,0,0,0,0,1,0,0,0,0,0%5D,%0A#  %5B0,0,0,0,0,0,0,1,1,1,0,0,0%5D,%0A#  %5B0,1,1,0,1,0,0,0,0,0,0,0,0%5D,%0A#  %5B0,1,0,0,1,1,0,0,1,0,1,0,0%5D,%0A#  %5B0,1,0,0,1,1,0,0,1,1,1,0,0%5D,%0A#  %5B0,0,0,0,0,0,0,0,0,0,1,0,0%5D,%0A#  %5B0,0,0,0,0,0,0,1,1,1,0,0,0%5D,%0A#  %5B0,0,0,0,0,0,0,1,1,0,0,0,0%5D%5D%0A#%0A# Given the above grid, return 6. Note the answer is not 11,%0A# because the island must be connected 4-directionally.%0A#%0A# Example 2:%0A# %5B%5B0,0,0,0,0,0,0,0%5D%5D%0A#%0A# Given the above grid, return 0.%0A#%0A# Note: The length of each dimension in the given grid does not exceed 50.%0A%0Aclass Solution(object):%0A    def maxAreaOfIsland(self, grid):%0A        %22%22%22%0A        :type grid: List%5BList%5Bint%5D%5D%0A        :rtype: int%0A        %22%22%22%0A        directions = %5B%5B-1,  0%5D, %5B 1,  0%5D, %5B 0,  1%5D, %5B 0, -1%5D%5D%0A%0A        def dfs(i, j, grid, area):%0A            if not (0 %3C= i %3C len(grid) and %5C%0A                    0 %3C= j %3C len(grid%5B0%5D) and %5C%0A                    grid%5Bi%5D%5Bj%5D %3E 0):%0A                return False%0A            grid%5Bi%5D%5Bj%5D *= -1%0A            area%5B0%5D += 1%0A            for d in directions:%0A                dfs(i+d%5B0%5D, j+d%5B1%5D, grid, area)%0A            return True%0A%0A        result = 0%0A        for i in xrange(len(grid)):%0A            for j in xrange(len(grid%5B0%5D)):%0A                area = %5B0%5D%0A                if dfs(i, j, grid, area):%0A                    result = max(result, area%5B0%5D)%0A        return result%0A

Create max-area-of-island.py