189. Rotate Array数组右移
来源:互联网 发布:java rmi 漏洞 修复 编辑:程序博客网 时间:2024/06/06 03:27
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]
.
Note:
Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
class Solution {public: void rotate(vector<int>& nums, int k) { vector<int> tmp; int len = nums.size(); k = k % len; for(int i = len-k; i < len; i++) { tmp.push_back(nums[i]); } for(int j = 0; j < len-k; j++) { tmp.push_back(nums[j]); } for(int k = 0; k < len; k++) { nums[k] = tmp[k]; } }};
0 0
- 189. Rotate Array数组右移
- 189. Rotate Array 数组右移K位
- 189Rotate Array 实现数组循环右移的代码
- 189. Rotate Array 旋转数组
- 189. Rotate Array 旋转数组
- LeetCode 189. Rotate Array(旋转数组)
- leetcode 189. Rotate Array-旋转数组
- 189. Rotate Array (旋转数组)
- LeetCode#189. Rotate Array(数组循环移位)
- leetcode 189. Rotate Array旋转数组
- Rotate Array数组旋转
- leetcode:Rotate Array旋转数组
- Rotate Array 数组的旋转
- 【LeetCode】Rotate Array 旋转数组
- Rotate Array 数组旋转 leetcode
- leetcode Rotate Array 旋转数组
- [C++]Rotate Array 旋转数组
- Rotate Array 部分旋转数组
- 乐观锁和悲观锁的区别
- java中命令模式
- erjinzhi
- 数据源配置之一
- SDUT 2878 Circle (高斯消元)
- 189. Rotate Array数组右移
- ubuntu 环境下搭建 scikit-learn 环境
- Leet Code OJ 28. Implement strStr() [Difficulty: Easy]
- sqlserver中All、Any和Some用法与区别
- activiti 23个表创建语句(一)续
- 第一次博客
- 将十进制数转化为二进制数
- CSS中overflow的用法
- Glide-图片的加载和缓存