Using Golang Slice

  • 0

    This is not the best solution.
    Just to share the solution.

    func rotate(nums []int, k int) {
    k %= len(nums)
    var length int = len(nums) - k
    var tmp []int = make([]int, 0)
    tmp = append(tmp, nums[length:]...)
    tmp = append(tmp, nums[:length]...)

    for i, n := range tmp {
    	nums[i] = n


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.