250x250
반응형
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

재 현

k번째 수 본문

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

'Coding test' 카테고리의 다른 글

가운데 글자 가져오기  (0) 2021.06.13
자바 배열 출력 오류 [I@15db9742  (0) 2021.06.13
행렬의 덧셈  (0) 2020.11.24
정수 제곱근  (0) 2020.11.24
파이썬을 파이썬답게  (0) 2020.11.20