Concise c# solution


  • 0
    M
        public int NumberOfArithmeticSlices(int[] A) {
            if(A.Length < 3) return 0;
            int l = 0, d = A[1] - A[0], r = 0;
            for(int i = 2; i < A.Length; i++) {
                var d1 = A[i] - A[i-1];
                if(d1 == d) {
                    r += ++l;
                } else {
                    d = d1;
                    l = 0;
                }    
            }
            return r;
        }
    }

Log in to reply
 

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