공부-codility

[Lesson] 2. Arrays - CyclicRotation

아직해떴다 2022. 8. 4. 15:46

소스코드 

if(A.length==0){
	return A;
}

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

while(K > 0){
	Integer temp = AList.get(AList.size()-1);
	AList.remove(AList.size()-1);
	AList.add(0, temp);
	K--;
}

for(int i = 0 ; i < AList.size() ; i++){
	A[i] = AList.get(i);
}
return A;