[algorithm] 뒤에서 5등까지

인철·2024년 2월 27일
0

algorithm

목록 보기
81/91
post-thumbnail

정수로 이루어진 리스트 num_list가 주어집니다. num_list에서 가장 작은 5개의 수를 오름차순으로 담은 리스트를 return하도록 solution 함수를 완성해주세요.

import java.util.*;

class Solution {
    public int[] solution(int[] num_list) {
        int[] answer = new int[5]; // 배열의 크기를 5로 지정
        Arrays.sort(num_list); // 기존 배열을 오름차순으로 정렬
        for(int i = 0; i < 5; i++){
            answer[i] = num_list[i];
        }
        return answer;
    }
}
profile
같은글이있어도양해부탁드려요(킁킁)

0개의 댓글