Created
June 15, 2018 14:03
-
-
Save s4553711/28cbf371cefa271198e69f3568ffb93e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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