Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- """
- :type image: List[List[int]]
- :type sr: int
- :type sc: int
- :type newColor: int
- :rtype: List[List[int]]
- """
- def convert(self, image, r, c, newColor, x_size, y_size):
- if r not in range(y_size) or c not in range(x_size):
- return
- if image[r][c] == self.init_color and (r, c) not in self.prev_seen:
- image[r][c] = newColor
- self.prev_seen.add((r, c))
- for x, y in ((r-1, c), (r+1, c), (r, c-1), (r, c+1)):
- self.convert(image, x, y, newColor, x_size, y_size)
- def floodFill(self, image, sr, sc, newColor):
- if not image:
- return
- y_size = len(image)
- x_size = len(image[0])
- self.init_color = image[sr][sc]
- self.prev_seen = set()
- self.convert(image, sr, sc, newColor, x_size, y_size)
- return image
Add Comment
Please, Sign In to add comment