LeetCode-Array-189. Rotate Array
来源:互联网 发布:支持php的web服务器 编辑:程序博客网 时间:2024/05/01 20:36
问题:https://leetcode.com/problems/rotate-array/
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].
思考:创建一个vector,依次push_back。
C++代码:
class Solution {public: void rotate(vector<int>& nums, int k) { int l=nums.size(); vector<int>result; if(l==1) return ; if(k>l) k%=l; for(int i=l-k;i<l;i++){ result.push_back(nums[i]); } for(int j=0;j<l-k;j++){ result.push_back(nums[j]); } nums=result; }};
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
- [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
- 质量控制之室内质控(IQC)和室间质评(EQA)
- 仿京东天猫的下拉刷新
- (十六)备忘录模式详解(都市异能版)
- 还有 13 天,苹果就要关上 HTTP 大门了
- java中的4种访问修饰符
- LeetCode-Array-189. Rotate Array
- <img>会随着窗口大小缩放
- Callable,Runnable比较及用法
- 同步和Java内存模型
- 大龄程序员的未来
- 银行卡规范
- 安卓透明状态栏小技巧
- openssl
- Go语言之append函数