class Solution {
public int[] solution(int[] num_list) {
int[] answer = {};
return answer;
}
}
해결법
방법 1
import java.util.*;
class Solution {
public List solution(int[] num_list) {
List<Integer> answer = new ArrayList<>();
Arrays.sort(num_list);
for (int i = 5; i < num_list.length; i++) {
answer.add(num_list[i]);
}
return answer;
}
}
방법 2
import java.util.*;
class Solution {
public int[] solution(int[] num_list) {
Arrays.sort(num_list);
int n = 5;
int[] answer = new int[num_list.length - n];
for (int i = n; i < num_list.length; i++){
answer[i - n] = num_list[i];
}
return answer;
}
}
방법 3
import java.util.*;
class Solution {
public int[] solution(int[] num_list) {
Arrays.sort(num_list);
int idx = 0;
int[] answer = new int[num_list.length - 5];
for (int i = 5; i < num_list.length; i++) {
answer[idx++] = num_list[i];
}
return answer;
}
}
뒤에서 5등 위로 Lv. 0