알고리즘 문제 풀기/Programmers
프로그래머스 - 탐욕법(Greedy) - 구명보트
bug_maker
2020. 1. 1. 16:02
프로그래머스 - 탐욕법(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 answer
pc 환경에서 코드를 보는 것을 권장합니다.