**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.**
这题比较简单,只要建一个数组,然后把原数组的值按照规律(公式)赋给新的数组,再把新数组的值赋给原数组就行了。
void rotate(int nums[], int n, int k) {
int nums1[n];
for (int y=0;y<n;y++){
nums1[(y+k+n)%n]=nums[y];
}
for (int i=0;i<n;i++){
nums[i]=nums1[i];
}
}