728x90
deque 를 이용해서 풀었고, 2명씩 탄다는 조건을 놓쳐서 조금 헤맸다.
from collections import deque
def solution(people, limit):
answer = 0
people = deque(sorted(people))
stack = [ ]
print(list(people))
while True:
if len(people)==0:
break
# 맨 뒤에랑 맨 앞이랑 합쳤는데 limit 넘으면 answer+=1, pop()
a = people[-1]
b = people[0]
if a+b>limit:
answer+=1
people.pop()
# 안넘으면 answer+=1, pop, popleft
else:
answer+=1
people.pop()
if len(people)==0:
break
people.popleft()
return answer728x90
'🟢 알고리즘 문제 풀이 > Programmers' 카테고리의 다른 글
| [파이썬] 프로그래머스 타겟 넘버 (0) | 2023.03.07 |
|---|---|
| [파이썬] 프로그래머스 N으로 표현 (0) | 2023.03.03 |
| [파이썬] 프로그래머스 모음사전 (0) | 2023.03.01 |
| [파이썬] 프로그래머스 소수 찾기 (0) | 2023.02.28 |
| [파이썬] 프로그래머스 프린터 (0) | 2023.02.27 |