189. Rotate Array
来源:互联网 发布:c语言必背基础程序 编辑:程序博客网 时间:2024/05/22 03:49
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) {if (k <= 0) return;int len = nums.size();k = k%len;int i = 0, j = len - k - 1;while (i < j){swap(nums[i++], nums[j--]);}i = len - k, j = len - 1;while (i < j){swap(nums[i++], nums[j--]);}i = 0, j = len - 1;while (i < j){swap(nums[i++], nums[j--]);}}};
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
- 关于系统签名的问题
- 使UILabel垂直考上对齐
- C#6新特性
- JAVA常用多线程知识大全(一)
- js中的函数和执行环境
- 189. Rotate Array
- qt QPalette的应用
- Apache 2.4在windows7系统的安装
- HttpServlet详解
- 易语言 客户组件post发送数据带所有信息
- 【SSH进阶之路】Struts + Spring + Hibernate 进阶开端(一)
- 309. Best Time to Buy and Sell Stock with Cooldown
- 9、单表数据查询----第2篇
- HashMap在多线程环境下偶然造成InfiniteLoop导致程序宕机