Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
519 B
0
Indexable
Never
public class Solution {
    public int solve(ArrayList<Integer> A) {
        ArrayList<Integer> B = new ArrayList<Integer>();
        for(int i=0;i<A.size();i++) {
            B.add(A.get(i));
        }
        Collections.sort(B);
        for(int i=0;i<A.size();i++) {
            if(A.get(i)!=B.get(i)) {
                int diff = Math.abs(A.get(i)-B.get(i));
                if(diff>1) {
                    return 0;
                } 
            }
        }
        
        return 1;
    }
}