[프로그래머스]K번째 수.java

전영서·2021년 9월 12일
0

Algorithm

목록 보기
27/89

1.문제

https://programmers.co.kr/learn/courses/30/lessons/42748

2.코드

import java.util.Arrays;

class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int[] answer = new int[commands.length];
        
        for(int tc=0; tc<commands.length; tc++){
            int len = commands[tc][1]-commands[tc][0]+1;
            int[] temp = new int[len];
            
            //copy
            for(int i=0; i<len; i++){
                temp[i] = array[commands[tc][0]-1+i];
            }
            //정렬
            Arrays.sort(temp);
            //저장
            answer[tc] = temp[commands[tc][2]-1];   
        }
        return answer;
    }
}

3.Review

문제 대로 하면 된다...

profile
꾸준히 성실하게

0개의 댓글