알고리즘 문제 풀이 / 프로그래머스 (programmers) - K번째 수
문제 링크
https://programmers.co.kr/learn/courses/30/lessons/42748
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
문제 풀이
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for(int i = 0; i < commands.length; i++){
int[] arr = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]);
Arrays.sort(arr);
answer[i] = arr[commands[i][2]-1];
}
return answer;
}
반응형
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스(programmers)] (Lv3) 여행경로 (1) | 2021.05.21 |
---|---|
[프로그래머스(programmers)] (Lv2) 전화번호 목록 (0) | 2021.05.20 |
[프로그래머스(programmers)] (Lv1) 완주하지 못한 선수 (0) | 2021.05.19 |
[프로그래머스(programmers)] (Lv2) 다리를 지나는 트럭 (1) | 2021.05.18 |
[프로그래머스(programmers)] (Lv2) 프린터 (0) | 2021.05.17 |
댓글