본문 바로가기
카테고리 없음

[JAVA/프로그래머스] > 코딩 기초 트레이닝 > 뒤에서 5등까지

by 93 DL 2024. 2. 16.

 

1번 풀이

1
2
3
4
5
6
7
8
    public int[] solution(int[] num_list) {
        Arrays.sort(num_list);
        int[] answer = new int[5];
        for(int i=0; i<5; i++) {
            answer[i] = num_list[i];
        }
        return answer;
    }
cs

 

 

2번 풀이

1
2
3
4
5
6
class Solution {
    public int[] solution(int[] num_list) {
        Arrays.sort(num_list);
        return Arrays.copyOfRange(num_list, 05);
    }
}
cs