LeetCode Rotate Array

BabbleDay posted @ 2015年7月17日 04:24 in 刷题防身 with tags python leetcode Rotate Array , 595 阅读

方法一 insert执行效率低

    def rotate(self, nums, k):
        for _ in range(k):
            nums.insert(0,nums[-1])
            del(nums[-1])
        return

 

方法二 list赋值

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

 

 

Avatar_small
Kris Thorkelson 说:
2019年12月24日 21:25

Kris Thorkelson, who began his career in the pharmaceutical industry in Winnipeg, Manitoba, operates several pharmacies, in addition to his real estate business. “As a leader, it is your role to praise employees who do a good job,” Thorkelson adds.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter