[자료구조] 방문 길이 파이썬 (hash)
def solution(dirs): x,y = 5,5 # start point mapping = {"U":(0,1), "D":(0,-1), "R":(1,0), "L":(-1,0)} visited = [[0 for _ in range(11)] for _ in range(11)] for i,d in enumerate(dirs): if 0
2021. 4. 24.
[자료구조] FloodFill 파이썬 (BFS, queue)
BFS from collections import deque def solution(n, m, image): cnt = 0 visited = [[False] * m for _ in range(n)] # visited table (col(m) x row(n)) dir = [[1,0], [0,1], [-1,0], [0,-1]] # 4-direction for i in range(n): for j in range(m): if not visited[i][j]: q = deque() # BFS-queue q.append([i,j]) visited[i][j] = True color = image[i][j] while q: x, y = q.popleft() for dx, dy in dir: xx, yy = x+dx,..
2021. 4. 23.