link

 

class Solution:
    def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:
        R, C = len(image), len(image[0])
        oldcolor = image[sr][sc]
        if oldcolor == color : return image
        def dfs(r, c):
            if image[r][c] == oldcolor :
                image[r][c] = color
                if r >= 1 : dfs(r-1, c)   # 좌
                if r+1 < R : dfs(r+1, c)  # 우
                if c >= 1 : dfs(r, c-1)   # 상
                if c+1 < C : dfs(r, c+1)  # 하
        
        dfs(sr, sc)
        return image
블로그 이미지

hjc_

୧( “̮ )୨

,