Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func rotLeft(a: [Int], d: Int) -> [Int] {
- var array: [Int] = []
- for i in 0 ..< a.count {
- let index = (i + d) % a.count
- array.append(a[index])
- }
- return array
- }
- rotLeft(a: [1,2,3,4,5], d: 4) // output [5, 1, 2, 3, 4]
Add Comment
Please, Sign In to add comment