44 leetcode - Rotate Array
来源:互联网 发布:微商城数据统计 编辑:程序博客网 时间:2024/06/05 22:36
#!/usr/bin/python# -*- coding: utf-8 -*-'''Rotate ArrayRotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].'''class Solution(object): def __rotate(self,nums,left,right): while left < right: tmp = nums[left] nums[left] = nums[right] nums[right] = tmp left += 1 right -= 1 def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: void Do not return anything, modify nums in-place instead. """ length = len(nums) if 0 == length or 0 == k % length: return k = k % length self.__rotate(nums,0,length - k - 1) self.__rotate(nums,length - k,length - 1) self.__rotate(nums,0,length - 1)if __name__ == "__main__": s = Solution() l = range(1,8) s.rotate(l,2) print l
0 0
- 44 leetcode - Rotate Array
- [leetcode][array] Rotate Array
- LeetCode[Array]: Rotate Image
- LeetCode:Rotate Array
- [LeetCode] Rotate Array
- *LeetCode-Rotate Array
- [LeetCode]189.Rotate Array
- Rotate Array - LeetCode - Java
- Rotate Array--Leetcode(Java)
- Leetcode--Rotate Array
- LeetCode: Rotate Array
- LeetCode Rotate Array
- Rotate Array(leetcode)
- leetcode Rotate Array
- Leetcode: Rotate Array
- [Leetcode]11 Rotate Array
- [LeetCode][189][Rotate Array]
- Leetcode:Rotate Array
- Node.js中同步函数异步编程
- unity发布APP到手机的屏幕显示方式
- HTTP协议经典详解
- 大数据需要学什么
- 网站502与504错误分析
- 44 leetcode - Rotate Array
- checkbox利用JQuer中 attr('checked', true)设置状态只有第一次有用
- oracle监听常见错误和解决思路
- 45 leetcode - Rotate Function
- C 的一点心得
- aspx网页验证文本框
- oracle操作的点点滴滴
- 常用hash函数解析及代码
- 二叉树结构数组表示法