classSolution:defrotate(self,nums: List[int],k:int) ->None:""" Do not return anything, modify nums in-place instead. """ k = k %len(nums) nums[:]= nums[-k:]+ nums[:-k]
in-place
classSolution:defrotate(self,nums: List[int],k:int) ->None: lens =len(nums)if k == lens:return k = k % lens self.reverse(nums, 0, lens-1) self.reverse(nums, 0, k -1) self.reverse(nums, k, lens-1)defreverse(self,nums,l,r):while l < r: nums[l], nums[r]= nums[r], nums[l] l +=1 r -=1
import functoolsclassSolution:defPrintMinNumber(self,numbers):ifnot numbers:return"" num =list(map(str, numbers)) cmp =lambdaa,b: 1if a + b > b + a else-1 num =sorted(num, key=functools.cmp_to_key(cmp))return''.join(num)