```
public int numberOfArithmeticSlices(int[] A) {
if( A.length < 3 ) return 0;
int cnt = 1, max = 0;
int diff = A[0]-A[1];
for(int i = 2; i < A.length; i++) {
if(A[i-1] - A[i] == diff) max += cnt++;
else {
/*reset count and diff */
diff = A[i-1] - A[i];
cnt = 1;
}
}
return max;
}
```