안녕하세요 !
https://programmers.co.kr/learn/courses/30/lessons/42885
파이썬은 그냥 배열로 풀면 pop(0) 할때 효율성에서 시간초과가 나더군요 …
그래서 deque로 하니 해결됐네요.
from collections import deque
def solution(people, limit):
answer = 0
people = deque(sorted(people))
while people:
if people[-1] + people[0] <= limit:
people.pop()
if people:
people.popleft()
answer += 1
elif people[-1] <= limit:
people.pop()
answer += 1
else:
people.pop()
return answer