Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created June 15, 2018 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s4553711/28cbf371cefa271198e69f3568ffb93e to your computer and use it in GitHub Desktop.
Save s4553711/28cbf371cefa271198e69f3568ffb93e to your computer and use it in GitHub Desktop.
class Solution {
public:
int numberOfArithmeticSlices(vector<int>& A) {
int count = 0;
int added = 0;
int n = A.size();
for(int i = 2; i < n; i++) {
if (A[i-1] - A[i] == A[i-2] - A[i-1]) {
count += ++added;
} else {
added = 0;
}
}
return count;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment