Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-03-19_01-08-21.png
51.2 KB
#medium

#N1630. Arithmetic Subarrays
problem link

#solution
class Solution {
public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {
List<Boolean> list = new ArrayList<>();

for(int i=0; i<l.length; i++){
int temp[] = new int[r[i]-l[i]+1];
for(int j=l[i]; j<=r[i]; j++){
temp[j-l[i]]=nums[j];
}
Arrays.sort(temp);
list.add(check(temp));
}

return list;
}
public boolean check(int[] arr){
for(int i=1; i<arr.length-1; i++){
if(arr[i]*2!=arr[i-1]+arr[i+1])
return false;
}

return true;
}
}
👍2