[アルゴリズム]プログラマー-kビット数/Java

4516 ワード

import java.util.*;
import java.io.*;

class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int len = commands.length;
        int[] answer = new int[len];
        
        
        for(int i = 0 ; i < len ; i++){

           int[] arr =  Arrays.copyOfRange(array, commands[i][0]-1 , commands[i][1]);
            Arrays.sort(arr);
            // System.out.print(Arrays.toString(arr));
            answer[i] = arr[commands[i][2]-1];
        }
        
        return answer;
    }
}