public static void rotate(int[] nums, int k) { k = k%nums.length; reverse(nums,0,nums.length); reverse(nums,0,k); reverse(nums,k,nums.length); } public static void reverse(int[] nums,int start,int end) { int temp ; //交换 while (start<end){ temp=nums[end-1]; nums[end-1]=nums[start]; nums[start]=temp; start++; end--; } }