You are viewing a single comment's thread. Return to all comments →
The most simpe solution I could think of
Swift: func rotateLeft(d: Int, arr: [Int]) -> [Int] { let movedIdx = d % arr.count //get amount of index 0 shift return arr.dropFirst(movedIdx) + arr.dropLast(arr.count - movedIdx) }
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
The most simpe solution I could think of
Swift: func rotateLeft(d: Int, arr: [Int]) -> [Int] { let movedIdx = d % arr.count //get amount of index 0 shift return arr.dropFirst(movedIdx) + arr.dropLast(arr.count - movedIdx) }