This is the second lesson in Codility; that is to rearrange an array to the right based on the number of steps given. It will be two input and I scored 100% for it.
public int[] solution (int[] A, int K){
int a = 0;
int[] sortA = A;
int x = 0;
while (x < K && x < A.length){
a = sortA[sortA.length - 1];
Arrays.copyOfRange(sortA, 0, sortA.length);
sortA = Arrays.copyOf(sortA, sortA.length);
System.arraycopy(sortA, 0, sortA, 1, sortA.length - 1);
sortA[0] = a;
System.err.println( x + " : " + Arrays.toString(sortA) + " - " + a);
x++;
}
return sortA;
};
100% CyclicRotation
You can get the code at
Bitbucket - git clone https://masteramuk@bitbucket.org/fullstacksdev/codility-cyclicrotation.git
Github - git clone https://github.com/masteramuk/codility-lessoncode.git
Thursday, January 9, 2020
Home »
Codility
,
Java
,
Open Source
,
Programming
,
Sample Code
,
Software Development
,
Tips and Trick
» Codility - CyclicRotation (Rotate an array to the right by a given number of steps)
0 comments:
Post a Comment