-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path1630.java
More file actions
24 lines (23 loc) · 716 Bytes
/
1630.java
File metadata and controls
24 lines (23 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {
List<Boolean> arr = new ArrayList<>();
for(int i=0;i<l.length;i++){
arr.add(Check(nums,l[i],r[i]));
}
return arr;
}
private static boolean Check(int[] nums, int from, int to){
int[] temp = new int[to-from+1];
for(int i=from;i<=to;i++){
temp[i%(to-from+1)] = nums[i];
}
Arrays.sort(temp);
int value = temp[1] - temp[0];
for(int i=2;i<temp.length;i++){
if(temp[i]-temp[i-1] != value){
return false;
}
}
return true;
}
}