189. Rotate Array
来源:互联网 发布:淘宝网购物女装连衣裙夏装 编辑:程序博客网 时间:2024/05/08 22:43
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]
.
class Solution {public: void rotate(vector<int>& nums, int k) { k=k%(nums.size()); vector<int> a(k,0); for(int i=nums.size()-k;i<nums.size();i++) a[i-nums.size()+k]=nums[i]; for(int i=nums.size()-1;i>=0;--i) nums[i]=nums[i-k]; for(int i=0;i<k;++i) nums[i]=a[i]; }};
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
- Open Source Threat Intelligence
- [bzoj3784]树上的路径
- QT GUI界面假死的处理
- LintCode- 单词切分
- 蓝桥杯_算法训练_K好数
- 189. Rotate Array
- 适配器模式
- UIUITableView头部图片拉伸放大效果
- id_rsa权限过高导致不能下载
- 2016蓝桥杯假期任务之《字串统计》
- swift 语法 集合
- 一个CXF集成SPRING的WEBSERVICE完整实例
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- 操作系统项目(一)获取内核源码