[프로그래머스] 구명보트
그리디 알고리즘
정렬 후 작은 값과 큰값 더한 후 비교
파이썬
def solution(people, limit):
i = 0
j = len(people) -1
cnt=0
people.sort()
while i<=j:
cnt+=1
if people[i] + people[j] <= limit:
i+=1
j-=1
return cnt
댓글남기기