LeetCode:Rotate Array
来源:互联网 发布:终极算法 改变世界 编辑:程序博客网 时间:2024/05/17 05:50
想了半天最后还是用了暴力解法,总觉得应该还有更巧妙的算法。
class Solution {public: void rotate(int nums[], int n, int k) { int temp; int i,j; int count; k=n-k%n;//将向右旋转变成向左旋转,但注意k的值有可能比n大 if(k==n) return; else{ count=0; while(count<k) { temp=nums[0]; for(i=1;i<n;i++) { nums[i-1]=nums[i]; } nums[n-1]=temp; count++; } } }};
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
- Cocos2d-x 3.3 的3D开发功能介绍
- 各种排序算法的分析及java实现
- pat1058 A+B in Hogwarts
- c#开发微信企业号的一些心得
- POJ3233解题报告
- LeetCode:Rotate Array
- 做产品16年,9条心得
- Binary Tree Inorder Traversal - Leetcode
- 使用GCD的dispatch_once创建单例
- MySQL数据库的服务器端卸载----->MySQL
- Cocos2d-x 3.0final 终结者系列教程22Cocos Studio动画编辑器的帧动画和骨骼动画详解
- C语言选择排序算法(升序)
- 【POJ2392】Space Elevator
- MySQL数据库的客户端安装----->NavicatforMySQL和SQLyog_Enterprise