[Programmers] 구명보트 - Java Solution

문제

  • https://programmers.co.kr/learn/courses/30/lessons/42885

Solution

import java.util.Arrays;

class Solution {
    public int solution(int[] people, int limit) {
        int answer = 0;
        
        Arrays.sort(people);
        int minValueIndex = 0;
        
        for(int maxValueIndex=people.length-1; maxValueIndex>=minValueIndex; maxValueIndex--) {
            
            if(people[maxValueIndex] + people[minValueIndex] <= limit) {
                minValueIndex++;
            }
            
            answer++;
        }

        return answer;
    }
}

Leave a comment