public class Solution { public int NumberOfArithmeticSlices(int[] A) { int curr = 0, sum = 0; for (int i = 2; i < A.Length; i++) if (A[i] - A[i - 1] == A[i - 1] - A[i - 2]) { curr += 1; sum += curr; } else { curr = 0; } return sum; } }
https://leetcode.com/problems/arithmetic-slices/#/description
时间: 2024-10-08 00:52:48