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
'Python 문제풀이 > LeetCode' 카테고리의 다른 글
617. Merge Two Binary Trees (DFS , 재귀) (0) | 2022.07.12 |
---|---|
695. Max Area of Island (DFS : 제일 큰 섬의 면적) (0) | 2022.07.11 |
567. Permutation in String ** (슬라이딩 윈도우) (0) | 2022.06.17 |
19. Remove Nth Node From End of List ** (링크드 리스트) (0) | 2022.06.16 |
876. Middle of the Linked List (0) | 2022.06.16 |