Simple Java Solution, 2ms


  • 0
    M
    public class Solution {
        public int numberOfArithmeticSlices(int[] A) {
            int[] B = new int[A.length];
            int count = 0;
            for(int i=2; i<A.length; i++) {
                if(A[i]-A[i-1]==A[i-1]-A[i-2]) {
                    B[i] = B[i-1]+1;
                    count += B[i];
                }
            }
            return count;
        }
    }
    

Log in to reply
 

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