Arithmetic Slices

Problem Id: 413 Difficulty: Medium


Intuition

Solution


class Solution:
    def numberOfArithmeticSlices(self, A: List[int]) -> int:
        counts = 0
        length = 0
        tmp = None

        for i in range(1, len(A)):
            if A[i-1] - A[i] == tmp:
                length += 1
            else:
                tmp = A[i-1] - A[i]
                length = 0
            counts += length
        return counts