반응형
from collections import deque
def solution(people, limit):
answer = 0
people.sort(reverse=True)
people = deque(people)
while len(people) > 1:
bigP = people.popleft()
smallP = people.pop()
if bigP + smallP <= limit:
answer += 1
else:
people.append(smallP)
answer += 1
if len(people) == 1:
answer += 1
return answer
반응형
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[파이썬][프로그래머스] 깊이/너비 우선 탐색(DFS/BFS) 타겟 넘버 (0) | 2023.01.11 |
---|---|
[파이썬][프로그래머스] 동적계획법(Dynamic Programming) 정수 삼각형 (0) | 2023.01.03 |
[파이썬][프로그래머스] 탐욕법(Greedy) 체육복 (0) | 2022.12.02 |
[파이썬][프로그래머스] 완전탐색 피로도 (0) | 2022.11.29 |
[파이썬][프로그래머스] 완전탐색 카펫 (0) | 2022.11.28 |
댓글