class Solution(object): def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: void Do not return anything, modify nums in-place instead. """ m=len(nums)-k nums=nums[m:]+nums[:m]
Idea is the join the last half list and front half list together.
First time I return nums[m:]+nums[:m] , but it's not what the test want. Then I simply change nums, but it didn't pass the test also.