Golang rotations solution


  • 0
    R
    func rotate(nums []int, k int)  {
        k = k % len(nums)
        count := 0
        for start:=0; count<len(nums); start++ {
            current := start
            prev := nums[start]
            for 1 == 1 {
                next := (current+k) % len(nums)
                temp := nums[next]
                nums[next] = prev
                prev = temp
                current = next
                count++
                if start == current {
                    break
                }
            }
        }
    }
    

Log in to reply
 

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