Skip to content

Instantly share code, notes, and snippets.

@XcqRomance
Created December 3, 2018 07:06
Show Gist options
  • Save XcqRomance/228968600ca32eb45fc0b52ae7c4aceb to your computer and use it in GitHub Desktop.
Save XcqRomance/228968600ca32eb45fc0b52ae7c4aceb to your computer and use it in GitHub Desktop.
3.旋转数组
void rotate(int* nums, int numsSize, int k) {
if (k <= 0 || numsSize <= 0) {
return;
}
for (int i = 0; i < k; i++) {
int temp = nums[numsSize - 1];
for (int j = numsSize - 1; j >= 1; j --) {
nums[j] = nums[j-1];
}
nums[0] = temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment