Skip to content

Commit 2f4bff8

Browse files
committed
Sync LeetCode submission Runtime - 32 ms (27.64%), Memory - 19.3 MB (19.48%)
1 parent 8ffe35f commit 2f4bff8

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
# Approach 1 - Depth-First Search (Recursive)
1+
# Approach 1: Depth First Search (Recursive)
22

3-
# Time: O(R*C)
4-
# Space: O(R*C)
3+
# Time: O(m * n)
4+
# Space: O(m * n)
55

66
class Solution:
77
def maxAreaOfIsland(self, grid: List[List[int]]) -> int:
88
seen = set()
9-
9+
1010
def area(r, c):
1111
if not (0 <= r < len(grid) and 0 <= c < len(grid[0]) and (r, c) not in seen and grid[r][c]):
1212
return 0
13-
13+
1414
seen.add((r, c))
15-
16-
return (1 + area(r-1, c) + area(r+1, c) + area(r, c+1) + area(r, c-1))
17-
18-
return max(area(r, c) for r in range(len(grid)) for c in range(len(grid[0])))
19-
15+
16+
return 1 + area(r + 1, c) + area(r - 1, c) + area(r, c + 1) + area(r, c - 1)
17+
18+
return max(area(r, c)
19+
for r in range(len(grid))
20+
for c in range(len(grid[0])))
2021

0 commit comments

Comments
 (0)