一开始自己写的总是Time limited exceeded,discuss里的这个方法真的是非常好,记录下来:
void reverse(int num[],int k)
{
int c, j, i;
for (i = 0, j = k-1; i<j; i++, j--)
{
c = num[i];
num[i] = num[j];
num[j] = c;
}
}
void rotate(int nums[], int n, int k) {
reverse(nums, n);
reverse(nums, k%n);
reverse(nums + k%n, n - k%n);
}
Runtime : 10ms