leetcode 189: Rotate Array
来源:互联网 发布:迅雷 知乎 编辑:程序博客网 时间:2024/05/06 15:25
Use queue to save the numbers need to be rotated. The problem means to rotate to the right direction, but I do it to the left direction, so I change k to n-(k%n).
class Solution {public: void rotate(vector<int>& nums, int k) { int n=nums.size(); k=n-(k%n); queue<int> q; int i,j; for(i=0;i<k;i++) q.push(nums[i]); for(j=0;i<n;i++,j++) nums[j]=nums[i]; while(!q.empty()) { nums[j++]=q.front(); q.pop(); } }};
0 0
- [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
- 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
- [Leetcode]#189 Rotate Array
- leetcode 189 Rotate Array
- 【LeetCode】189Rotate Array
- LeetCode 189 Rotate Array
- 解决 ffmpeg yasm not found, use --disable-yasm for a crippled build
- nyoj--图像有用区域
- nyoj--水池数目
- pg 时间函数
- poj-1321
- leetcode 189: Rotate Array
- poj-2251
- 转贴 poj分类
- poj-1562
- poj-1426(转)
- zzuli训练赛_05_13-K
- zzuli训练赛_05_13-D
- 辽宁省赛——杨鲁斯卡尔专场 -F
- 辽宁省赛——杨鲁斯卡尔专场-J