1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class Solution: def numberOfArithmeticSlices(self, nums: List[int]) -> int: ans = 0
data = [] for i in range(len(nums)-1): data.append(nums[i+1]-nums[i]) data.append(-3000) left = data[0] cnt = 0
for i in data: if i != left: cnt = 0 left = i if i == left: cnt += 1 if cnt > 1: ans += cnt-1 return ans
|