Development/알고리즘
[프로그래머스 | Javascript] Lv.2 구명보트
레오나르도 다빈츠
2025. 1. 13. 17:25
function solution(people, limit) {
people.sort((a, b) => a - b)
let count = 0
while (people.length !== 0) {
if (people[0] + people[people.length-1] <= limit) {
count += 1
people.shift()
people.pop()
} else {
count += 1
people.pop()
}
}
return count;
}