RotateArray
来源:互联网 发布:手机发票制作软件 编辑:程序博客网 时间:2024/06/05 09:48
class Solution4 {//正确运行public void rotate(int[] nums, int k) {int n = nums.length;k = k % n;int start = 0;int period = k;while (start < period) {int bak = nums[start];int i = start;while (true) {int j = (i + n - k) % n;if (j == start)break;period = Math.min(period, j);nums[i] = nums[j];i = j;}nums[i] = bak;start++;}}}
public class Solution1 {//超时public void rotate(int nums[], int k) {int temp;int n = nums.length;for (int step = 0; step < k; step++) {temp = nums[n - 1];for (int i = n - 1; i > 0; --i) {nums[i] = nums[i - 1];}nums[0] = temp;}}
0 0
- RotateArray
- leetcode189.RotateArray
- 算法之001RotateArray
- python值和引用——【LeetCode】RotateArray
- 剑指Offer RotateArray 旋转数组的最小数字
- POJ 2352 Stars(树状数组)
- 【JAVA学习】3 JAVA包
- IOS开发之UIView总结
- POJ 3903 Stock Exchange (LIS模版题)
- 全 Javascript 的 Web 开发架构:MEAN
- RotateArray
- 关于定于应用和初始化不匹配的问题
- 字符串-07. 说反话-加强版 (20)
- C数据类型变量范围 变量存储 数据溢出
- java中抽象类和接口的区别
- ORACLE9i_性能调优基础五(Sizing Other SGA structures)
- Pixhawk 源码笔记
- Hdoj 1075 What Are You Talking About 【MAP】
- jQuery.i18n使用过程中IE浏览器一直报脚本错