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.
"""
k%=len(nums)
self.rotateMethod(nums,0,len(nums)-1)
self.rotateMethod(nums,0,k-1)
self.rotateMethod(nums,k,len(nums)-1)
def rotateMethod(self,nums,l,r):
while l<r:
tmp=nums[l]
nums[l]=nums[r]
nums[r]=tmp
l+=1
r-=1
def rotate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: void Do not return anything, modify nums in-place instead.
"""
k%=len(nums)
self.rotateMethod(nums,0,len(nums)-1)
self.rotateMethod(nums,0,k-1)
self.rotateMethod(nums,k,len(nums)-1)
def rotateMethod(self,nums,l,r):
while l<r:
tmp=nums[l]
nums[l]=nums[r]
nums[r]=tmp
l+=1
r-=1