leetcode-189. Rotate Array
来源:互联网 发布:管家婆数据导入工具 编辑:程序博客网 时间:2024/04/30 07: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.
思路:字符串右移操作,(x^ty^t)^t = yx
class Solution { //思路:《程序员编程艺术第一~二十七章集锦与总结(教你如何编程)(by_July)定稿版》原题 // (X^tY^t)^t = YX;public: void rotate(vector<int>& nums, int k) { int length = nums.size(); k = k%length; reversalNum(nums,0,length-k-1); reversalNum(nums,length-k,length-1); reversalNum(nums,0,length-1); } void reversalNum(vector<int>& nums,int begin,int end) { int temp; while(begin < end) { temp = nums[begin]; nums[begin] = nums[end]; nums[end] = temp; begin++; end--; } }};
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
- 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
- leetcode-189. Rotate Array
- Leetcode 189. Rotate Array
- leetcode 189. Rotate Array
- java基础(33)--java.util.Scanner应用详解
- linux下未满足依赖关系错误(1)
- bootstrap popover稍微修改
- AsyncHttpClient POST上传文件
- AD硬件电路模块设计——PS7219及单片机的SPI接口电路
- leetcode-189. Rotate Array
- (4.6.11.7)使用BUCK 编译Android应用
- Rift音频
- linux下修改mysql密码的方法
- matlab 常用 api(四)
- android 中layer-list的用法
- 异常处理
- win7,win8 下PLSQL developer 连接不上64位Oracle 的解决方法 不安装orcal 使用PLSQL的组件 使用它可以不安装oracle连接数据库
- ACM--酷酷的单词--CSU 1505--湖南第十届省赛