[LeetCode] Rotate Array
2015-07-13 19:58
281 查看
Question:
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、扩展:
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].
1、题型分类:
2、思路:
3、时间复杂度:
4、代码:
public class Solution { public void rotate(int[] nums, int k) { int len=nums.length; k=k%len; int [] temp=new int[len+k]; System.arraycopy(nums, 0, temp, k, len); System.arraycopy(temp, len, temp, 0, k); System.arraycopy(temp, 0, nums, 0, len); } }
5、优化:
6、扩展:
相关文章推荐
- hbase ERROR: wrong number of arguments (3 for 4)
- 关于Eclipse的SVN插件(Subclipse)历史版本乱码的问题
- 详细教你如何重写tabcontrol控件
- 网页布局,左固定右自适应宽
- Tomcat 设置 Java File encoding
- WordPress高级自定义布局的内容编辑器模板
- HTTP长连接与短连接
- PHP第六课 使用方法数组
- hive 模拟update 操作
- OC 基础之—(NSDate, 类目 Category,协议Protocol, 延展,委托代理)
- Ubuntu 下一个disk清理保护
- hbase操作
- eclipse中出现"确认切换透视图“的原因
- OC 核心语法罗列
- C++中将构造函数或析构函数定义为private
- Decorator模式
- swift 可选类型,强制拆包,隐性拆包
- css硬件加速
- R语言ggplot2包之画散点图
- js中函数声明与表达式