알고리즘 문제풀이/Programmers - 자바
프로그래머스 - 구명보트
올리브영
2023. 4. 21. 17:25
728x90
반응형
import java.util.*;
class Solution {
public int solution(int[] people, int limit) {
int answer = 0;
int k = 0;
Arrays.sort(people);
for(int i=people.length-1; i>=k; i--){
if(people[i] + people[k] <=limit){
answer++;
k++;
}
else{
answer++;
}
}
return answer;
}
}
728x90
반응형