티스토리 뷰
programmers.co.kr/learn/courses/30/lessons/42885
코딩테스트 연습 - 구명보트
무인도에 갇힌 사람들을 구명보트를 이용하여 구출하려고 합니다. 구명보트는 작아서 한 번에 최대 2명씩 밖에 탈 수 없고, 무게 제한도 있습니다. 예를 들어, 사람들의 몸무게가 [70kg, 50kg, 80kg, 5
programmers.co.kr
from collections import deque
def solution(people, limit):
answer = 0
people.sort()
people = deque(people)
while(people):
if len(people) == 1:
people.pop()
else:
heavy = people.pop()
light = people.popleft()
if (heavy + light) > limit:
people.appendleft(light)
answer += 1
return answer
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스] 기능개발 - Python (0) | 2021.03.26 |
---|---|
[프로그래머스] 튜플 - Python (0) | 2021.03.25 |
[프로그래머스] 다리를 지나는 트럭 - Python (0) | 2021.03.25 |
[프로그래머스] 주식가격 - Python (0) | 2021.03.25 |
[프로그래머스] 프린터 - Python (0) | 2021.03.25 |