Concise golang solution


  • 0
    P
    func rotate(nums []int, k int)  {
        k = k % len(nums)
        reverse(nums)
        reverse(nums[:k])
        reverse(nums[k:])
    }
    
    func reverse(nums []int) {
        l := 0
        r := len(nums) - 1
        
        for l < r {
            nums[l],nums[r] = nums[r],nums[l]
            l++
            r--
        }
    }
    

Log in to reply
 

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