LeetCode: Rotate Array
来源:互联网 发布:软件 开发 编辑:程序博客网 时间:2024/05/17 21:44
while(k>=n){ k=k-n; } std::rotate(nums, nums+n-k, nums+n);
......
具体可以看stl_algo.h,有forward, bidirectional, random iterator版本。
我不明白的是forward_iterator版本:
_ForwardIterator __first2 = __middle; do{ std::iter_swap(__first, __first2); ++__first; ++__first2; if (__first == __middle) __middle = __first2;} while (__first2 != __last); __first2 = __middle; while (__first2 != __last){ std::iter_swap(__first, __first2); ++__first; ++__first2; if (__first == __middle) __middle = __first2; else if (__first2 == __last) __first2 = __middle;}
第一个do while loop的作用是什么。
这么写:
void myswap(int& m, int& n){m = m^n;n = m^n;m = m^n;}void rotate(int nums[], int n, int k) {while (k>=n){k = k - n;}if (k <= 0) return;k = n - k;int p = k;int s = 0;int e = n;while (p!=n){myswap(nums[s], nums[p]);s++; p++;if (s==k){k = p;}else if(p==n){p = k;}}}
提交也过了。
0 0
- [leetcode][array] Rotate Array
- LeetCode[Array]: Rotate Image
- LeetCode:Rotate Array
- [LeetCode] Rotate Array
- *LeetCode-Rotate Array
- [LeetCode]189.Rotate Array
- Rotate Array - LeetCode - Java
- Rotate Array--Leetcode(Java)
- Leetcode--Rotate Array
- LeetCode: Rotate Array
- LeetCode Rotate Array
- Rotate Array(leetcode)
- leetcode Rotate Array
- Leetcode: Rotate Array
- [Leetcode]11 Rotate Array
- [LeetCode][189][Rotate Array]
- Leetcode:Rotate Array
- LeetCode: Rotate Array
- Ubuntu下安装cgal4.5.2计算几何库
- Adobe Photoshop CS6提示”无法完成请求,因为文件格式模块不能解析该文件“
- 几个项目规划畅想etc.
- opencv2在视频帧序列中运用鼠标extract rectangle region
- 自学数据挖掘十大算法之PageRank
- LeetCode: Rotate Array
- 3.5学习内容 宽带测速原理,RESTful架构,rpc个人理解
- 增强现实追加2
- innodb优化转载篇
- 利用citeUlike管理文献
- 新的一年飘了一下,就过来了. 在过去的一年,大家都找到了自已的幸福吗?
- LeetCode之Multiply Strings
- Java课程设计之你画我猜
- 说说第一份工作