Problem Solving/Programmers

[Level 2] 구명보트

kmkunk 2022. 4. 6. 12:54
import java.util.*;

class Solution {
    public int solution(int[] people, int limit) {
        int answer = 0;
        int start = 0;
        int end = people.length-1;
        
        Arrays.sort(people);
        
        while(start<=end) {
            start += people[start]+people[end]<=limit ? 1 : 0;
            end--;
            answer++;
        }
        
        return answer;
    }
}