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
코드
import java.util.Arrays;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] result = new int[commands.length];
for (int i = 0; i < commands.length; i++) {// 행
int from_num = commands[i][0];// ~부터
int to_num = commands[i][1];// ~까지
int get_num = commands[i][2];// 가져올 번호
int[] temp_array = Arrays.copyOfRange(array, from_num - 1, to_num);
Arrays.sort(temp_array);
result[i] = temp_array[get_num - 1];
}
// System.out.println(Arrays.toString(result));
return result;
}
}
'프로그래머스 > LEVEL 1' 카테고리의 다른 글
[프로그래머스/LEVEL1] 나머지가 1이 되는 수 찾기 (0) | 2022.01.19 |
---|---|
[프로그래머스/LEVEL1] 최대공약수와 최소공배수 (0) | 2022.01.19 |
[프로그래머스/LEVEL1] 예산 (0) | 2022.01.19 |
[프로그래머스/LEVEL1] 약수의 합 (0) | 2022.01.19 |
[프로그래머스/LEVEL1] 약수의 개수와 덧셈 (0) | 2022.01.19 |