Rotate array works on my machine, but not online


  • 0
    B
      def rotate(self, nums, k):
            nums = nums[-k:] + nums[:-k]

  • 0
    C

    Your code is not quite right...

    What if k is greater than len(nums)?

    For example:

    rotate([1,2,3],5) should return [2,3,1] while your code will return [1,2,3] instead.


Log in to reply
 

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