leetcode hot100 数组:轮转数组

本题轮转数组,其实反转三次就行了

class Solution {

int nums\[\];

int k;

public void rotate(int\[\] nums, int k) {

if(k>=nums.length){

k=k%nums.length;

}

this.nums= nums;

this.k = k;

int bounder = nums.length-k;

reverse(0,bounder-1);

reverse(bounder,nums.length-1);

reverse(0,nums.length-1);

}

public void reverse(int start,int end){

while(start<end){

int temp = numsstart;

numsstart = numsend;

numsend = temp;

end--;

start++;

}

}

}