python easy to understand


  • 0
    X
    class Solution(object):
        def numberOfArithmeticSlices(self, A):
            """
            :type A: List[int]
            :rtype: int
            """
            l = len(A)
            i = 0
            b = 0
            s = []
            c = 0
            while i<l-2:
                if A[i+1]-A[i] == A[i+2]-A[i+1]:
                    c += 1
                    i += 1
                else:
                    s.append(c)
                    i += 1
                    c = 0
            if c != 0:
                s.append(c)
            l1 = len(s)
            for j in range(l1):
                while s[j]>0:
                    b += s[j]
                    s[j] -= 1
            return b
    

Log in to reply
 

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