class Solution(object):
def floodFill(self, image, sr, sc, newColor):
"""
:type image: List[List[int]]
:type sr: int
:type sc: int
:type newColor: int
:rtype: List[List[int]]
"""
list_1 = len(image)
list_2 = len(image[0])
oldColor = image[sr][sc]
def turn_1(i ,j):
if 0 <= i < list_1 and 0 <= j < list_2 and image[i][j]==oldColor:
image[i][j] = newColor
turn_1(i + 1, j)
turn_1(i, j + 1)
turn_1(i - 1, j)
turn_1(i, j - 1)
else:
return
if oldColor != newColor:
turn_1(sr,sc)
return image
Sol = Solution()
print Sol.floodFill([[1,1,1],[1,1,0],[1,0,1]],1,1,2)
0,
1,题目需求:
2,类似于之前做过的一道计算岛屿最大面积的题目。不同的是岛屿为已经探查过的点置0,这里置为新的值。