Untitled
unknown
plain_text
2 years ago
519 B
3
Indexable
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; } }
Editor is loading...