Coding test

구명보트

본명은이점례 2021. 11. 17. 16:42
728x90
def solution(people, limit):
    people.sort()
    answer = 0
    i = 0
    j = len(people)-1
    while i <= j:
        answer += 1
        if people[j] + people[i] <= limit:
            i += 1
        j -= 1

    return answer

 

가장 몸무게가 큰 사람과 작은 사람의 값을 더해 limit보다 작으면 둘 다 태우고 아니면 한 사람만 태운다

 

728x90