재 현
k번째 수 본문
728x90
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int [commands.length];
int[] p = {};
int i;
for (i=0; i<commands.length; i++)
{
p = Arrays.copyOfRange(array,commands[i][0]-1,commands[i][1]);
Arrays.sort(p);
answer[i] = p[commands[i][2]-1];
}
return answer;
}
}
* 사용 개념
Arrays.copyOfRange(arr, 2 ,4 ); 2번째 인자(포함)부터 3번째 인자(미포함) 앞까지 추출)
int[] answer = new int [arrays.length]; // 해당배열 길이만큼의 배열 선언
728x90
'Coding test' 카테고리의 다른 글
가운데 글자 가져오기 (0) | 2021.06.13 |
---|---|
자바 배열 출력 오류 [I@15db9742 (0) | 2021.06.13 |
행렬의 덧셈 (0) | 2020.11.24 |
정수 제곱근 (0) | 2020.11.24 |
파이썬을 파이썬답게 (0) | 2020.11.20 |