Skip to content

Commit c6ac275

Browse files
Create 1630-arithmetic-subarrays.java
1 parent e8edc96 commit c6ac275

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

java/1630-arithmetic-subarrays.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {
3+
List<Boolean> res = new ArrayList<>();
4+
5+
for(int i = 0; i < l.length; i++){
6+
int[] subArray = Arrays.copyOfRange(nums, l[i], r[i]+1);
7+
Arrays.sort(subArray);
8+
int diff = subArray[1] - subArray[0];
9+
boolean isArithmatic = true;
10+
for(int j = 1; j < subArray.length; j++){
11+
if(subArray[j] - subArray[j-1] != diff){
12+
isArithmatic = false;
13+
break;
14+
}
15+
}
16+
res.add(isArithmatic);
17+
}
18+
return res;
19+
}
20+
}

0 commit comments

Comments
 (0)