프로그래머스 - 탐욕법(Greedy) - 구명보트
작성언어: Python3
def solution(people, limit): answer = 0 people.sort() light = 0 heavy = len(people) - 1 cnt = 0 while(light < heavy): if(people[light] + people[heavy] <= limit): cnt += 1 light += 1 heavy -= 1 else: heavy -= 1 answer = len(people) - cnt return answerpc 환경에서 코드를 보는 것을 권장합니다.
'알고리즘 문제 풀기 > Programmers' 카테고리의 다른 글
| 프로그래머스 - 탐욕법(Greedy) - 큰 수 만들기 (0) | 2019.12.31 |
|---|---|
| 프로그래머스 - 탐욕법(Greedy) - 조이스틱 (0) | 2019.12.29 |
| 프로그래머스 - 탐욕법(Greedy) - 체육복 (0) | 2019.12.28 |