lettcode189Rotate Array
来源:互联网 发布:顺丰速运成本数据分析 编辑:程序博客网 时间:2024/06/06 00:21
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
0 0
- lettcode189Rotate Array
- array
- Array#-
- Array#[]
- Array#<<
- Array
- array
- Array
- array
- Array
- array
- array
- array
- array()
- Array
- Array
- Array
- Array
- java MyBatis报错Parameter Maps collection does not contain value for xxx
- centos7下安装tomcat apr
- String.indexof(str)的用法
- 不要再使用MD5和SHA1加密密码了!
- 4、重建二叉树
- lettcode189Rotate Array
- Linux问题集
- AD进行行PCB DRC检查时,软件提示...report_drc.xsl不存在
- 设计模式之代理模式
- Runtime.getRuntime().exec();
- python3 .format()函数
- caffe︱深度学习参数调优杂记+caffe训练时的问题+dropout/batch Normalization
- Objective-C与JavaScript交互的那些事
- Zookeeper系列(九)Zookeeper开源客户端之ZKClient和Curator简介