def numberOfArithmeticSlices(self, A):
"""
:type A: List[int]
:rtype: int
"""
opt, i = [0,0], 1
for j in xrange(2,len(A)):
if A[j]A[j1] == A[j1]A[j2]:
opt.append(opt[j1]+i)
i += 1
else:
opt.append(opt[j1])
i = 1
return opt[1]
Python DP solution

@zhan430 Why not use a variable instead of an array?
class Solution(object): def numberOfArithmeticSlices(self, A): curr, sum = 0, 0 for i in range(2,len(A)): if A[i]A[i1] == A[i1]A[i2]: curr += 1 sum += curr else: curr = 0 return sum