Skip to content

Commit

Permalink
Add: #6 구명보트 - 유이서
Browse files Browse the repository at this point in the history
  • Loading branch information
yuiseo authored Nov 30, 2024
1 parent 423209b commit 8e0bfcf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions greedy/구명보트/유이서.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from collections import deque
def solution(people, limit):
answer = 0
people = deque(sorted(people,reverse=True))

while len(people)>1:
if people[-1]+people[0]<=limit:
people.pop()
people.popleft()
answer+=1
else:
people.popleft()
answer+=1

if len(people)==1:
answer+=1

return answer

0 comments on commit 8e0bfcf

Please sign in to comment.