My Normal C Solution


  • 0
    S
    int numberOfArithmeticSlices(int* A, int ASize) {
        if (ASize < 3) return 0;
        int i,ele = 2,count = 0;
        int d = A[1] - A[0];
        for(i = 1; i < ASize - 1; i++){
            int t_d = A[i+1] -A[i];
            if (t_d == d ) {
                ele++;
                if (i != ASize - 2) continue;
            }
            
            if (ele >= 3){
                count+= (ele-2)*(ele-1)/2;
            }
            d = t_d;
            ele = 2;
        }
        
        return count;
    }
    

Log in to reply
 

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