Skip to content

Commit 3972b53

Browse files
committed
Do daily
1 parent 2bf1540 commit 3972b53

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

my-submissions/h302 v1.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution:
2+
def minArea(self, image: List[List[str]], x: int, y: int) -> int:
3+
def dfs(x: int, y: int, cords: List[int] = [x, y, x, y]) -> None :
4+
if not (0 <= x < len(image)) or not (0 <= y < len(image[0])) :
5+
return
6+
if image[x][y] == "0" :
7+
return
8+
9+
if x < cords[0] :
10+
cords[0] = x
11+
elif x > cords[2] :
12+
cords[2] = x
13+
14+
if y < cords[1] :
15+
cords[1] = y
16+
elif y > cords[3] :
17+
cords[3] = y
18+
19+
image[x][y] = "0"
20+
dfs(x - 1, y, cords)
21+
dfs(x + 1, y, cords)
22+
dfs(x, y + 1, cords)
23+
dfs(x, y - 1, cords)
24+
25+
output = [x, y, x, y]
26+
dfs(x, y, output)
27+
return (output[2] - output[0] + 1) * (output[3] - output[1] + 1)

0 commit comments

Comments
 (0)