Coding test

k번째 수

본명은이점례 2021. 6. 13. 13:27
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