본문 바로가기

PROGRAMMERS26

[프로그래머스/파이썬] 옹알이 (1) 내 풀이 from collections import dequedef solution(babbling): answer = 0 capable = ["aya", "ye", "woo", "ma"] # 조카가 말할 수 있는 단어 alpha = ["a", "e", "m", "o", "w", "y"] # 말할 수 있는 단어를 구성하는 알파벳 for bbl in babbling: # 단어마다 초기화 word = deque() # 글자를 쌓아가는 큐 good = True # 가능한 단어였는지 # 글자를 하나씩 큐에 넣으면서, for w in bbl: # 가능한 알파벳이 아니면 불가능한 단어임을 표시하고 끝 .. 2025. 2. 9.
[프로그래머스/파이썬] 게임 맵 최단거리 내 풀이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.
[프로그래머스/파이썬] 퍼즐 게임 챌린지 내 풀이def solution(diffs, times, limit): answer = 0 # i-1에서 index 문제가 나지 않도록 0 삽입 diffs.insert(0, 0) times.insert(0, 0) # limit을 넘는지 확인하는 함수 : 넘지 않으면 True 넘으면 False def pnp(level, diffs, times, limit): total_time = 0 for i in range(1, len(diffs)): total_time += max(diffs[i]-level, 0) * (times[i] + times[i-1]) + times[i] return total_time  메모- 2025. 2. 4.
[프로그래머스/파이썬] 주차 요금 계산 내 풀이from math import ceildef solution(fees, records): in_dict = {} # 차 번호 : 주차 시작 시간 (분단위) time_dict = {} # 차 번호 : 총 주차 시간 (분단위) basic_time, basic_fee, per_time, per_fee = fees # 시간을 분단위로 변환하는 함수 def time_to_minute(time): h, m = map(int, time.split(":")) return h*60 + m # 총 시간을 요금으로 변환하는 함수 def minute_to_fee(total_time): if total_time  메모- 2025. 2. 3.
[프로그래머스/파이썬] 택배상자 내 풀이from collections import dequedef solution(order): answer = 0 conv_main = deque([i for i in range(1, len(order)+1)]) # 원래 메인 컨베이어 벨트 (Queue) conv_aux = deque() # 보조 컨베이어 벨트 (Stack) order = deque(order) # 택배 실을 순서 while True: # 메인 컨베이어 벨트에 택배가 있고, 실어야 할 택배와 메인 컨베이어 첫 번째가 같을 때 if conv_main and order[0] == conv_main[0]: order.popleft() conv_ma.. 2025. 1. 31.