구명보트

108번뇌·2020년 12월 24일

https://easybrother0103.tistory.com/125

풀었음.

import java.util.*;
class Solution {
    public int solution(int[] people, int limit) {
        int answer = 0;
        int length = people.length;
        Arrays.sort(people);

        int start = 0; int end = length - 1;

        for(int i=0; i<length; i++)
        {
            if(start>end)
            {
                break;
            }

            if((people[end] + people[start] <= limit))
            {
                start++;
            }
            end--;
            answer++;
        }

        return answer;
    }
}

익힐것 :
1. Arrays.sort() : 오름차순 정렬.

profile
내일 아침 눈을 떳을 때, '기대되는 오늘 하루를 만들기 위해' 나는 오늘도 생각하고 고민한다.

0개의 댓글