Why my Python Answer is wrong with [1],0 ? But it is right in my IDLE


  • 0
    Y

    class Solution:
    def rotate(self,nums,k):
    lenth=len(nums)
    if lenth<=1:
    return nums
    else:
    return nums[lenth-k:lenth]+nums[0:lenth-k]


  • 0
    Z

    @return nothing, please modify the nums list in-place.

    This method return nothing, so you have to replace the list

    def rotate(self, nums, k):
    nums[:] = nums[len(nums) - k % len(nums) : len(nums)] + nums[0 : len(nums) - k % len(nums)];


  • 0
    Y

    Thank you very much!


Log in to reply
 

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