class Solution { public: void rotate(int nums[], int n, int k) { k = k%n; reverse(nums,0,n-k-1); reverse(nums,n-k,n-1); reverse(nums,0,n-1); } void reverse(int nums[],int s,int e) { int mid = (s+e)/2; for(;s<=mid;s++,e--) { int temp = nums[s]; nums[s] = nums[e]; nums[e] = temp; } } };