[프로그래머스] 정렬 - K번째수 (자바)

Rena·2022년 4월 12일
0

알고리즘 문제풀이

목록 보기
27/45
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++) {
			int[] arr = Arrays.copyOfRange(array, commands[i][0]-1 , commands[i][1]);
			Arrays.sort(arr);
			answer[i] = arr[commands[i][2]-1];
		}
		return answer;
	}

	public static void main(String[] args) {
		Solution st = new Solution();
		int[] array = {1,5,2,6,3,7,4};
		int[][] commands = {{2,5,3},{4,4,1},{1,7,3}};
		st.solution(array,commands);
	}
}
profile
일을 사랑하고 싶은 개발자

0개의 댓글