[프로그래머스/파이썬] 게임 맵 최단거리
내 풀이from collections import dequedef solution(maps): answer = 0 n, m = len(maps[0]), len(maps) direction = [(0,1), (0,-1), (1,0), (-1,0)] # 가야 할 방향 def bfs(x, y): queue = deque() queue.append((x,y)) while queue: x,y = queue.popleft() for dx, dy in direction: nx, ny = x+dx, y+dy if 0 메모자주 풀어야 익숙해지지!
2025. 2. 6.
[프로그래머스/파이썬] 석유 시추
내 풀이from collections import dequedef solution(land): answer = 0 m, n = len(land[0]), len(land) visited = [[0]*m for _ in range(n)] directions = [(0,1), (0,-1), (1,0), (-1,0)] answer_list = [0] * m # x 위치에 시추했을 때 얻을 수 있는 석유의 양을 바로바로 추가해줌 def bfs(x, y): queue = [(x,y)] visited[y][x] = 1 visited_x = {x} # 방문한 x를 저장해 해당 x에 count만큼 더해줌 count = 1 ..
2025. 2. 6.