Easy SWIFT solution


  • 0
    B
    class Solution {
        func numberOfArithmeticSlices(_ A: [Int]) -> Int {
            var count = 1
            var res = 0
            if A.count <= 2
            {
                return 0
            }
            else {
                for n in 1..<A.count-1
                {
                    if ((A[n] - A[n-1]) == (A[n+1] - A[n]))
                    {
                        res += count
                        count += 1
                    }
                    else
                    {
                        count = 1
                    }
                }
             return res   
            }
        }
    }
    

Log in to reply
 

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