Rotate array works on my machine, but not online

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

  • 0

    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.