Programmers - K번째 수

[Java] Programmers - K번째 수

  • 문제 링크

  • 나의 답:

    import java.util.*;
      
    class Solution {
        static public int[] solution(int[] array, int[][] commands) {
            int[] answer = new int[commands.length];
      
      
      
            for (int i = 0; i < commands.length; i++) {
                ArrayList<Integer> a = new ArrayList<>();
      
                int x = commands[i][0];
                int y = commands[i][1];
                int k = commands[i][2];
      
                for (int j = x; j <= y; j++) {
                    a.add(array[j-1]);
                }
      
                Collections.sort(a);
                answer[i] = a.get(k-1);
            }
      
            return answer;
        }
    }
      
    
  • 결과: 스크린샷 2021-01-20 오후 5 44 26