class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] answer = {};
return answer;
}
}
해결법
방법 1
class Solution {
public int[] solution(int[] arr, int[][] queries) {
for (int[] query : queries) {
int s = query[0];
int e = query[1];
int k = query[2];
for (int i = s ; i <= e ; i++) {
if (i % k == 0) {
arr[i]++;
}
}
}
return arr;
}
}
방법 2
class Solution {
public int[] solution(int[] arr, int[][] queries) {
for (int i = 0; i < queries.length; i++) {
for (int j = queries[i][0]; j <= queries[i][1]; j++) {
if (j % queries[i][2] == 0) {
arr[j] += 1;
}
}
}
return arr;
}
}
수열과 구간 쿼리 4 Lv. 0