내 답안
import java.util.*;
class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] arr1 = new int[queries.length];
Arrays.fill(arr1, Integer.MAX_VALUE);
for(int i = 0; i < queries.length; i++) {
for (int j = queries[i][0]; j <= queries[i][1]; j++){
if( arr[j] > queries[i][2]) {
if(arr1[i] > arr[j])
arr1[i] = arr[j];
}
}
if(arr1[i] == Integer.MAX_VALUE)
arr1[i] = -1;
}
return arr1;
}
}
Java
복사
다른 사람 풀이법
import java.util.Arrays;
class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] answer = new int[queries.length];
Arrays.fill(answer, -1);
for (int idx = 0; idx < queries.length; idx++) {
int[] query = queries[idx];
int s = query[0], e = query[1], k = query[2];
for (int i = s; i <= e; i++) {
if (k < arr[i]) {
answer[idx] = answer[idx] == -1 ? arr[i] : Math.min(answer[idx], arr[i]);
}
}
}
return answer;
}
}
Java
복사