-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm1992.py
24 lines (21 loc) · 954 Bytes
/
m1992.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def findFarmland(self, land: List[List[int]]) -> List[List[int]]:
output:List[List[int]] = []
for r in range(len(land)) :
for c in range(len(land[0])) :
if land[r][c] \
and (r == 0 or not land[r - 1][c]) \
and (c == 0 or not land[r][c - 1]) :
output.append([r, c, r, c])
rRight, cRight = r, c
while True :
if rRight >= len(land) or land[rRight][c] == 0 :
output[-1][2] = rRight - 1
break
rRight += 1
while True :
if cRight >= len(land[0]) or land[r][cRight] == 0 :
output[-1][3] = cRight - 1
break
cRight += 1
return output