189. Rotate Array

来源:互联网 发布:归并排序算法过程图解 编辑:程序博客网 时间:2024/05/16 05:09

题目:https://leetcode.com/problems/rotate-array/

代码:

public class Solution {    public void rotate(int[] nums, int k) {        k = k%nums.length;        int[] temp = new int[k];        for(int i=nums.length-k;i<nums.length;i++)            temp[i-nums.length+k] = nums[i];        for(int i=nums.length-k-1;i>=0;i--)            nums[i+k] = nums[i];        for(int i=0;i<k;i++)            nums[i] = temp[i];    }}1ms
0 0
原创粉丝点击