-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflood_fill.py
24 lines (24 loc) · 939 Bytes
/
flood_fill.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 floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]:
oldColor = image[sr][sc]
imageWidth = len(image)
imageHeight = len(image[0])
if oldColor == newColor:
return image
##### Helper FXN ####################
#####################################
def flood_fill_inner(x, y):
if image[x][y] == oldColor:
image[x][y] = newColor
if x > 0:
flood_fill_inner(x-1, y)
if y > 0:
flood_fill_inner(x, y-1)
if x < imageWidth-1:
flood_fill_inner(x+1, y)
if y < imageHeight-1:
flood_fill_inner(x, y+1)
#####################################
#####################################
flood_fill_inner(sr,sc)
return image