Thursday, February 28, 2019

LeetCode 189. Rotate Array

'''
Given an array, rotate the array to the right by k steps, where k is non-negative.

'''
class Solution(object):
    def rotate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: None Do not return anything, modify nums in-place instead.
        """
        for i in range(k):
            temp = nums.pop()
            nums.insert(0, temp)

No comments:

Post a Comment