思路:见题解https://leetcode-cn.com/problems/arithmetic-slices/solution/deng-chai-shu-lie-hua-fen-by-leetcode/
class Solution(object):
def numberOfArithmeticSlices(self, A):
"""
:type A: List[int]
:rtype: int
"""
if len(A) <= 2:
return 0
dp = [0] * len(A)
for i in range(2, len(A)):
if A[i] - A[i-1] == A[i-1] - A[i-2]:
dp[i] = 1 + dp[i-1]
return sum(dp)