L2 : 구명보트 Python

jhyunn·2023년 1월 20일
0

Programmers

목록 보기
47/69

L2 : 구명보트 Python

https://school.programmers.co.kr/learn/courses/30/lessons/42885

def solution(people, limit) :
    people.sort()
    cnt = 0
    i, j = 0, len(people)-1
    
    while i<j: # 양 끝에서 한 칸씩 이동하며 비교
        if people[i] + people[j] <= limit: # 오른쪽 끝이 큰 값이므로 오른쪽을 줄여나감
            i += 1
        j -= 1
        cnt += 1
    
    if i == j:
        return cnt + 1
    return cnt

#그리디 #greedy

profile
https://github.com/Sungjeonghyun

0개의 댓글