189. Rotate Array
来源:互联网 发布:杭州正规淘宝运营公司 编辑:程序博客网 时间:2024/06/04 19:35
Rotate 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]
.
Hint:
Could you do it in-place with O(1) extra space?
Could you do it in-place with O(1) extra space?
题目大意:旋转一个列表,要求空间复杂度O(1)。
思路:使用Python list 的切片
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 %= n nums[:] = nums[n-k:] + nums[:n-k]
nums[:]的作用见这里
0 0
- Leetcode - Array - 189. Rotate Array
- 189. Rotate Array leetcode(array)
- LeetCode-Array-189. Rotate Array
- [LeetCode]189.Rotate Array
- [Leetcode] 189.Rotate Array
- LeetCode 189. Rotate Array
- 【LeetCode】189.Rotate Array
- [leetcode] 189.Rotate Array
- 【leetcode】189. Rotate Array
- Leetcode 189. Rotate Array
- 189. Rotate Array LeetCode
- 189. Rotate Array
- [LeetCode]189. Rotate Array
- 189. Rotate Array
- leetcode-189.-Rotate Array
- 189. Rotate Array
- 189. Rotate Array
- 189. Rotate Array
- webpack学习笔记
- Inxi:一个功能强大的获取 Linux 系统信息的命令行工具
- Java数值计算的总结
- 2017阿里实习生招聘编程题之相亲约会
- 关于jquery的$.ajax的基本用法总结
- 189. Rotate Array
- 分类系列之感知器学习算法PLA 和 口袋算法Pocket Algorithm
- 如何解决在使用Eclipse在配置xml文件时,xml文件底部不出现namespace等选项。
- sqlite3编程—处理二进制blob
- 在Windows上安装Python以及Numpy、Matplotlib等模块
- Linux 上 GDM 登录界面如何适应高分屏
- OpenGL由FOVY计算FOVX
- 计算机网络面试题
- JavaScript简介与基本语法