Skip to content

Commit 449cfe7

Browse files
committed
day 7
1 parent 3d2287f commit 449cfe7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

733. Flood Fill.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]:
3+
oldColor = image[sr][sc]
4+
r, c = len(image), len(image[0])
5+
6+
visited =[]
7+
for i in range(r):
8+
visited.append([0]*c)
9+
10+
def FloodFill(x,y):
11+
if image[x][y] == oldColor and visited[x][y] == 0:
12+
image[x][y] = newColor
13+
visited[x][y] = 1
14+
if x>0:
15+
FloodFill(x-1, y) #top node
16+
if y<c-1:
17+
FloodFill(x, y+1) #right node
18+
if x<r-1:
19+
FloodFill(x+1, y) #bottom node
20+
if y>0:
21+
FloodFill(x, y-1) #left node
22+
FloodFill(sr,sc)
23+
return image

0 commit comments

Comments
 (0)