Created
September 13, 2018 08:55
-
-
Save CreatiCoding/ee1761bba483ff4aa71bee4677631df4 to your computer and use it in GitHub Desktop.
[codility] CyclicRotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function solution(A, K) { | |
let arr = []; | |
// write your code in JavaScript (Node.js 8.9.4) | |
if(A.length === K || K === 0 || A.length === 0){ | |
return A; | |
} | |
for(let i = 0 ; i < K ; i ++ ){ | |
let pre = []; | |
pre[0] = A.pop(); | |
A = pre.concat(A); | |
} | |
return A; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment