[필요개념]
> 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));
}
}
'프로그래머 ,백준, 유튜브, 문제' 카테고리의 다른 글
소수 중 최대값 / 일반수 중 최소값 (0) | 2022.09.27 |
---|---|
소수 찾기_프로그래머스 (0) | 2022.09.27 |
최대공약수와 최소공배수_프로그래머스 (0) | 2022.09.27 |
신규아이디 추천_프로그래머스 (0) | 2022.09.27 |
시저암호_프로그래머스 (0) | 2022.09.26 |
댓글