LeetCode-【DFS】解题技巧

LeetCode题目:面试题 08.10. 颜色填充

    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]]
        """

        def dfs(image,sr,sc,oldColor,newColor):
            if image[sr][sc] == newColor:
                return
            image[sr][sc] = newColor
            d = [[-1,0],[1,0],[0,-1],[0,1]]
            for i in d:
                x,y=sr+i[0],sc+i[1]
                if x>=0 and x=0 and y

 

你可能感兴趣的:(LeetCode)