728x90
나의 풀이
from collections import deque
def solution(people, limit):
people = deque(sorted(people, reverse=True))
answer = 0
while people:
if len(people) > 1 and people[0] + people[-1] <= limit:
people.pop()
people.popleft()
answer += 1
return answer
pop 없이 index를 활용한 풀이
def solution(people, limit) :
answer = 0
people.sort()
a = 0
b = len(people) - 1
while a < b :
if people[b] + people[a] <= limit :
a += 1
answer += 1
b -= 1
return len(people) - answer
반응형
'Coding Test > Programmers' 카테고리의 다른 글
[프로그래머스/파이썬] 단속카메라 (0) | 2022.06.07 |
---|---|
[프로그래머스/파이썬] 섬 연결하기 (0) | 2022.06.07 |
[프로그래머스/파이썬] 큰 수 만들기 (0) | 2022.06.07 |
[프로그래머스/파이썬] 조이스틱 (0) | 2022.06.06 |
[프로그래머스/파이썬] 체육복 (0) | 2022.06.06 |