0413.cpp (420B)
1 class Solution { 2 public: 3 int numberOfArithmeticSlices(vector<int> &nums) { 4 int total = 0, crnt, cdiff = INT_MIN; 5 for (int i = 1; i < nums.size(); i++) { 6 int diff = nums[i] - nums[i - 1]; 7 if (diff != cdiff) { 8 crnt = 0; 9 cdiff = diff; 10 continue; 11 } 12 total += ++crnt; 13 } 14 return total; 15 } 16 };