개발/코딩

[프로그래밍] 프로그래머스 예제문제 풀어보기 <K번째수> 성공

mabb 2022. 5. 25. 16:22
반응형

 

 

 

 

 

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
32
33
import java.util.Arrays;
 
class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int[] answer = new int[commands.length];
    
        
        for(int i =0 ; i<commands.length ; i++){
            
            System.out.println("-----------");
            
            int startIndex = commands[i][0]-1;
            int endIndex = commands[i][1];
            int value =  commands[i][2]-1
            
            int[] ArrayTemp = Arrays.copyOfRange(array,startIndex,endIndex);
            Arrays.sort(ArrayTemp);
            
          answer[i] = ArrayTemp[value];
            
            
            for(int j = 0 ; j<ArrayTemp.length ; j++){
                System.out.println(ArrayTemp[j]);
            }
 
        }
        
        
        
        
        return answer;
    }
}
cs

 

 

반응형