본문 바로가기
💻 하나씩 차곡차곡/프로그래머스 (Python)

[프로그래머스/Lv2/Python] 구명보트

by 뚜루리 2024. 1. 22.
728x90
320x100
def solution(people, limit):
    answer = 1
    
    people.sort()
    
    weigth = 0
    for i in people:
        if limit < weigth + i:
            answer += 1
            weigth = i
        else :
            weigth += i
    
    return answer

일케 짰는데 테스트 통과하고 정확성 22퍼센트대로 ㅋㅋㅋㅋㅋㅋㅋ거의 틀린거나 다름 없이 됨.

 

다른 분 풀이를 가지고 왔다........

def solution(people, limit):

    people.sort()
    start, end = 0, len(people)-1
    count = 0

    while start <= end:
        count += 1
        if (people[start] + people[end] <= limit):
            start += 1
            end -= 1 
        else:
            end -= 1

    return count
728x90
320x100