1992. 找到所有的农场组
作者:互联网
从两边延伸,退耕还林
def find_farmland(land):
m, n, res = len(land), len(land[0]), []
for i in range(m):
for j in range(n):
if land[i][j] == 1:
r, c = i, j
while r < m - 1 and land[r + 1][j] == 1:
r = r + 1
while c < n - 1 and land[i][c + 1] == 1:
c = c + 1
res.append([i, j, r, c])
for n1 in range(i, r + 1):
for n2 in range(j, c + 1):
land[n1][n2] = 0
return res```
标签:1992,找到,res,农场,while,len,range,land,n1 来源: https://blog.csdn.net/haoshan4783/article/details/121427955