Scribbling

프로그래머스: 구명보트 본문

Computer Science/Coding Test

프로그래머스: 구명보트

focalpoint 2021. 10. 21. 20:07

몸무게로 줄을 세우고, 돼지와 홀쭉이를 매칭시켜준다.

def solution(people, limit):
    answer = 0
    people.sort(reverse=True)
    i, j = 0, len(people) - 1
    while i <= j:
        if people[i] + people[j] <= limit:
            answer += 1
            i += 1
            j -= 1
        else:
            answer += 1
            i +=1
    return answer