博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Rotate Array
阅读量:4074 次
发布时间:2019-05-25

本文共 556 字,大约阅读时间需要 1 分钟。

Rotate Array

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.

Java代码:

public class Solution {    public void rotate(int[] nums, int k) {        int len = nums.length;		if (0 == len || 1 == len || 0 == k) {			return;		}		int move = k % len;		int[] save = new int[move];		for(int i=0;i
=move;i--){ nums[i]=nums[i-move]; } for(int i=0;i
 

转载地址:http://xpuni.baihongyu.com/

你可能感兴趣的文章
Python学习笔记之数据类型
查看>>
Python学习笔记之特点
查看>>
shell 快捷键
查看>>
VIM滚屏操作
查看>>
EMC 2014存储布局及十大新技术要点
查看>>
linux内核内存管理(zone_dma zone_normal zone_highmem)
查看>>
将file文件内容转成字符串
查看>>
循环队列---数据结构和算法
查看>>
优先级队列-数据结构和算法
查看>>
链接点--数据结构和算法
查看>>
servlet中请求转发(forword)与重定向(sendredirect)的区别
查看>>
Spring4的IoC和DI的区别
查看>>
springcloud 的eureka服务注册demo
查看>>
eureka-client.properties文件配置
查看>>
MODULE_DEVICE_TABLE的理解
查看>>
platform_device与platform_driver
查看>>
platform_driver平台驱动注册和注销过程(下)
查看>>
.net强制退出主窗口的方法——Application.Exit()方法和Environment.Exit(0)方法
查看>>
c# 如何调用win8自带的屏幕键盘(非osk.exe)
查看>>
build/envsetup.sh 简介
查看>>