【leetcode❤python】 189. Rotate Array
#-*- 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)
【leetcode❤python】 189. Rotate Array的更多相关文章
- 【leetcode❤python】 396. Rotate Function
#-*- coding: UTF-8 -*- #超时# lenA=len(A)# maxSum=[]# count=0# while count ...
- <LeetCode OJ> 189. Rotate Array
189. Rotate Array Total Accepted: 55073 Total Submissions: 278176 Difficulty: Easy Rotate an array o ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【LeetCode】189. Rotate Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 切片 递归 日期 题目地址:https://leet ...
- 【LeetCode】189 - Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- 【easy】189. Rotate Array
题目标签:Array 题目给了我们一个数组 和 k. 让我们 旋转数组 k 次. 方法一: 这里有一个很巧妙的方法: 利用数组的length - k 把数组 分为两半: reverse 左边和右边的数 ...
- 【leetcode❤python】 88. Merge Sorted Array
#-*- coding: UTF-8 -*-class Solution(object): def merge(self, nums1, m, nums2, n): "& ...
- 【leetcode❤python】26. Remove Duplicates from Sorted Array
#-*- coding: UTF-8 -*-class Solution(object): def removeDuplicates(self, nums): "&quo ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
随机推荐
- java关键字之final
final表示不能修改. final修饰的方法不能被重写, final修饰的类不能被继承并且类里的所有方法都是final,成员变量可以是final或者不是final. final修饰的成员变量不可以改 ...
- ios枚举规范
- haproxy para config
.. from http://www.cnblogs.com/dkblog/archive/2012/03/13/2393321.html 常用配置选项: OPTION 选项: option http ...
- MS SQL 两种分页
------ row number ---------- ------ row number ---------- declare @pageSize int,@pageIndex int ; sel ...
- ListView遍历每个Item出现NullPointerException的异常
在使用ListView过程中我们有时候需要遍历取得每个Item项中的一些数据(比如每个Item里面有TextView,需要获取它的文本等等),但是我们在遍历过程中经常会遇到NullPointerExc ...
- Hotelling T2检验和多元方差分析
1.1 Hotelling T2检验 Hotelling T2检验是一种常用多变量检验方法,是单变量检验的自然推广,常用于两组均向量的比较. 设两个含量分析为n,m的样本来自具有公共协方差阵的q维正态 ...
- C++11基于范围的for循环
C++11包含一种新的 for 循环,称为基于范围的 for 循环,可以简化对数组元素的遍历.格式如下: for(Type VarName : Array){ //每个元素的值会依次赋给 VarNam ...
- infoq - neo4j graph db
My name is Charles Humble and I am here at QCon New York 2014 with Ian Robinson. Ian, can you introd ...
- Hash
创建(特殊的) Hash[] Hash[‘a’,1,’b’,2]->yes Hash[‘a’,1,’b’,’b’]->no Hash[[[‘a’,1],[‘b’,2]]]->yes ...
- uexQQ插件学习心得
uexQQ插件学习心得 uexQQ插件的作用:通过qq可以分享图文,音乐,应用到相应的qq空间.支持手机客户端分享和手机webQQ分享.下面我们就来看一看他的一些方法. 我们先说一下分享的步骤,这个步 ...