공부-codility

[Lesson] 4. PermCheck

아직해떴다 2022. 8. 8. 11:35

소스코드 

List<Integer> AList = new ArrayList<Integer>();
for(int i= 0 ; i < A.length ; i ++){
	AList.add(A[i]);
}
Collections.sort(AList);

int result = 1;
if(AList.get(0) != 1){
	result = 0;
}
else{
	if(AList.size() > 1){
		for(int i = 1 ; i < AList.size() ; i ++){
			if((AList.get(i) - AList.get(i-1)) != 1){
				result = 0;
				break;
			}
		}
	}
}

System.out.println(result);