Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
534 B
3
Indexable
Never
public int solve(int[] A) {
        
        int n = A.length;
        boolean flag = false;
        
        if(n == 1)
           return 1;
        
        for(int i = 1 ; i < n ; i++){
            
            if(A[i] < A[i-1]){
                int temp = A[i];
                A[i] = A[i-1];
                A[i-1] = temp;
                if(Math.abs(A[i-1]-A[i]) > 1){
                    flag = true;
                    break;
                }
            }
        }//loop
        
       
        return flag ? 0 : 1;
    }