I can't understand why the runtime of this code beats only 6.83 % of all CPP submissions.. is there a faster way to implement this??

'''

class Solution {

public:

int numberOfArithmeticSlices(vector<int>& A) {

int n = A.size();

```
if (n < 3)
return 0;
int prevcount = 0;
int totalcount = 0;
// Arithmetic slices must be consecutive numbers
for (int i = 2; i < n; ++i){
if (A[i] - A[i-1] == A[i-1] - A[i-2]){
prevcount++;
}
else prevcount = 0;
totalcount+=prevcount;
}
return totalcount;
}
```

};

'''