class FloodFill:

    def floodFill(self, image, sr, sc, newColor):
        row, col = len(image), len(image[0])
        color = image[sr][sc]
        if color == newColor:
            return image

        def dfs(r, c):
            if image[r][c] == color:
                image[r][c] = newColor

                if r >= 1:
                    dfs(r - 1, c)
                if r + 1 < row:
                    dfs(r + 1, c)
                if c >= 1:
                    dfs(r, c - 1)
                if c + 1 < col:
                    dfs(r, c + 1)

        dfs(sr, sc)
        return image


obj = FloodFill()
print(obj.floodFill([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 2))
