Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:
- newColor = color
- prevColor = image[sr][sc]
- def fill(r, c):
- if r < 0 or c < 0 or r > len(image) - 1 or c > len(image[0]) - 1:
- return
- # check if already visited
- if image[r][c] == newColor:
- return
- # check if the cell is cock-blocked:
- if image[r][c] == prevColor:
- image[r][c] = newColor
- else:
- return
- fill(r - 1, c)
- fill(r, c - 1)
- fill(r + 1, c)
- fill(r, c + 1)
- fill(sr, sc)
- return image
Add Comment
Please, Sign In to add comment