#-*- coding: UTF-8 -*-
#由于题目要求不返回任何值,修改原始列表,
#因此不能直接将新生成的结果赋值给nums,这样只是将变量指向新的列表,原列表并没有修改。
#需要将新生成的结果赋予给nums[:],才能够修改原始列表
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.
"""
n=len(nums)
k=k%n
if nums!=None:
nums[:]=nums[n-k:]+nums[:n-k]
print nums
sol=Solution()
sol.rotate([1,2], 5)
相关文章
- 189. Rotate Array 从右边开始翻转数组
- 189. Rotate Array
- 【leetcode❤python】26. Remove Duplicates from Sorted Array
- LeetCode算法题-Rotate Array(Java实现)
- LeetCode: Reverse Words in a String && Rotate Array
- [LeetCode]题解(python):026-Remove Duplicates from Sorted Array
- 【LeetCode】915. Partition Array into Disjoint Intervals 解题报告(Python)
- [LeetCode] 189. Rotate Array 旋转数组
- C++ STL@ list 应用 (leetcode: Rotate Array)
- 【LeetCode】108. Convert Sorted Array to Binary Search Tree 解题报告 (Java & Python)