본문 바로가기
프로그래머 ,백준, 유튜브, 문제

K번째 수_프로그래머스

by 리승우 2022. 9. 27.

[필요개념]

> Arrays.copyOfRange

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[] array2 = Arrays.copyOfRange(array,commands[i][0]-1,commands[i][1]);
                Arrays.sort(array2);
                answer[i] += array2[commands[i][2]-1];
            }

        return answer;
    }
}

    public class Hello {
        public static void main(String[] args) {
            Solution test = new Solution();
            int[] o = {1,5,2,6,3,7,4};
            int[][] p = {{2,5,3},{4,4,1},{1,7,3}};
            System.out.println(test.solution(o,p));
        }
    }

댓글