Super simple O(n) run time O(1) space python solution


  • 0
    W
    class Solution(object):
        def numberOfArithmeticSlices(self, A):
            """
            :type A: List[int]
            :rtype: int
            """
            count = 0
            total = 0
            for i in range(2, len(A)):
                if (A[i] - A[i - 1]) == (A[i - 1] - A[i - 2]):
                    count += 1
                    total += count 
                else:
                    count = 0
            return total 
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.