K 번째 수

  • K 번째 수 —- > 문제
  • 풀이 ↓
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {
    public int[] solution(int[] array, int[][] commands) {
		List<Integer> l = new ArrayList<Integer>();
		for(int i = 0; i<commands.length;i++) {
			int a = commands[i][0];
			int b = commands[i][1];
			int c = commands[i][2];
			
			int[] temp = Arrays.copyOfRange(array, a-1, b); //배열 자르기
			Arrays.sort(temp); //정렬
			l.add(temp[c-1]);
		}
		int[] result = new int[l.size()];
		int size = 0;
		for(Integer value : l) {
			result[size++] = value;
		}
		return result;
	}
}