Created
May 24, 2015 20:06
-
-
Save rootid/ff2d3975d73e308e8f59 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static void reverse (int nums[],int start,int end) { | |
while(start < end) { | |
int tmp = nums[start]; | |
nums[start] = nums[end]; | |
nums[end] = tmp; | |
start++; | |
end--; | |
} | |
} | |
public static void rotate(int[] nums, int k) { | |
int n = nums.length; | |
k %= n; | |
reverse(nums,0,n-1); | |
reverse(nums,0,k-1); | |
reverse(nums,k,n-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment