목록큐 (5)
컴공생의 다이어리

[프로그래머스] 주식가격 - 파이썬(Python) from collections import deque def solution(prices): queue = deque(prices) answer = [] while queue: price = queue.popleft() sec = 0 for q in queue: sec += 1 if price > q: break answer.append(sec) return answer https://programmers.co.kr/learn/courses/30/lessons/42584 코딩테스트 연습 - 주식가격 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수..

[프로그래머스] 다리를 지나는 트럭 - 파이썬(Python) def solution(bridge_length, weight, truck_weights): on_bridge = [0] * bridge_length answer = 0 while on_bridge: answer += 1 on_bridge.pop(0) if truck_weights: if sum(on_bridge) + truck_weights[0]

[프로그래머스] 프린터 - 파이썬(Python) def solution(priorities, location): priorities = [(v, idx) for idx, v in enumerate(priorities)] count = 0 while True: if priorities[0][0] == max(priorities)[0]: count += 1 if priorities[0][1] == location: break priorities.pop(0) else: priorities.append(priorities.pop(0)) return count https://programmers.co.kr/learn/courses/30/lessons/42587 코딩테스트 연습 - 프린터 일반적인 프린터는 인쇄 요..

[프로그래머스] 기능개발 - 파이썬(Python) import math def solution(progresses, speeds): answer = [] progress_day = [math.ceil((100 - x) / y) for x, y in zip(progresses, speeds)] count = 0 for i in progress_day: if i > count: answer.append(1) count = i else: answer[-1] += 1 return answer https://programmers.co.kr/learn/courses/30/lessons/42586 코딩테스트 연습 - 기능개발 프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비..

큐(Queue) 큐는 대기줄과 유사하다. 맛집의 줄을 서 있는 사람들이 있다고 할 때, 제일 먼저 들어갈 수 있는 사람은 먼저 온 사람이다(이때, 새치기는 없음). 나중에 줄을 선 사람은 마지막에 식당에 들어간다. 이러한 구조를 선입선출(FIFO, First In First Out)구조라고 한다. 파이썬 큐 예제 from collections import deque # 큐 구현을 위해 deque 라이브러리 사용 queue = deque() queue.append(5) queue.append(1) queue.append(4) queue.popleft()# 제일 앞에 있는 원소(5) 제거 queue.append(7) queue.append(2) queue.popleft() queue.append(3) pri..