내가 짠 코드
class Solution {
public:
int numberOfArithmeticSlices(vector<int>& A) {
if(A.size()<3) return 0;
int ans = 0;
int i,diff=A[1]-A[0],j,count=2;
for(i=1;i<=A.size()-2;i++){
if(A[i+1]-A[i]!=diff || i==A.size()-2){
if(A[i+1]-A[i] ==diff) count ++;
for(j=3;j<=count;j++){
ans += count+1-j;
}
count = 2;
diff = A[i+1] - A[i];
}
else count ++;
}
return ans;
}
};
'Problem Solving > 리트코드' 카테고리의 다른 글
[LeetCode] Longest Word in Dictionary through DeletingSolution (0) | 2021.02.22 |
---|---|
[LeetCode] Linked List Cycle (0) | 2021.02.08 |
[LeetCode] Number of 1 Bits (0) | 2021.02.08 |
[LeetCode] Squares of a Sorted Array (0) | 2021.01.29 |
[LeetCode] 541. Reverse String II (0) | 2021.01.27 |