정수로 이루어진 리스트 num_list가 주어집니다. num_list에서 가장 작은 5개의 수를 오름차순으로 담은 리스트를 return하도록 solution 함수를 완성해주세요.
sort로 정렬하고, 5번까지의 배열을 리스트에 담아주면 되지않을까
import java.util.*;
class Solution {
public int[] solution(int[] num_list) {
List<Integer> list = new ArrayList<>();
int idx = 0;
Arrays.sort(num_list);
for(int i = 0 ; i < 5 ; i++){
list.add(num_list[idx++]);
}
int[] answer = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
answer[i] = list.get(i);
}
return answer;
}
}