clear python solution O(n)


  • 0
    Z

    class Solution(object):
    def numberOfArithmeticSlices(self, A):
    count=0;
    dem=0;
    if len(A)<3:
    return count
    for x in range(1,len(A)-1):
    if (A[x]-A[x-1])==(A[x+1]-A[x]):
    dem+=1
    count+=dem
    else:
    dem=0;
    return count


Log in to reply
 

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