Skip to content

Commit b8889df

Browse files
committed
Runtime: 1416 ms (Top 90.80%) | Memory: 33.1 MB (Top 49.64%)
1 parent 615cf3e commit b8889df

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1+
# Runtime: 1416 ms (Top 90.80%) | Memory: 33.1 MB (Top 49.64%)
12
class Solution:
2-
3+
34
def findFarmland(self, land: List[List[int]]) -> List[List[int]]:
45
n = len(land)
56
m = len(land[0])
67

78
groups = []
89
visited = set()
9-
10+
1011
for y in range(n):
1112
for x in range(m):
1213
if land[y][x] == 0:
1314
continue
14-
15+
1516
if (y, x) in visited:
1617
continue
17-
18+
1819
q = collections.deque()
1920
q.append((y, x))
2021
visited.add((y, x))
21-
22+
2223
while q:
2324
cy, cx = q.popleft()
24-
25+
2526
for dy, dx in ((0, 1), (1, 0)):
2627
if (cy + dy, cx + dx) in visited:
2728
continue
28-
29+
2930
if 0 <= cy + dy < n and 0 <= cx + dx < m:
3031
if land[cy + dy][cx + dx] == 1:
3132
q.append((cy + dy, cx + dx))
3233
visited.add((cy + dy, cx + dx))
3334

3435
groups.append([y, x, cy, cx])
35-
36-
return groups
36+
37+
return groups

0 commit comments

Comments
 (0)