Created
December 3, 2018 07:06
-
-
Save XcqRomance/228968600ca32eb45fc0b52ae7c4aceb to your computer and use it in GitHub Desktop.
3.旋转数组
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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