Rotate Array in Swift

前端 未结 10 831
终归单人心
终归单人心 2021-01-05 16:45

While exploring algorithms in Swift, couldn\'t find algorithm for array rotation in swift without using funcs shiftLeft / shiftRight.

C has

10条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 17:15

    We can use Slice

    func rotLeft(a: [Int], d: Int) -> [Int] {
        let slice1 = a[..

提交回复
热议问题