Golang slices makes this too easy


  • 0
    M
    func rotate(nums []int, k int)  {
        k=k%len(nums)
        if k!=0{
            copy(nums,append(nums[len(nums)-k:],nums[:len(nums)-k]...))
        }
    }
    

    Beats around 92-100% of all go solutions


Log in to reply
 

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