Created
June 17, 2014 21:00
-
-
Save iwilbert/3a97e8dc2ec528a15602 to your computer and use it in GitHub Desktop.
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
public void rotate(int[][] matrix) { | |
if(matrix == null) | |
return; | |
int N = matrix.length; | |
for(int i = 0; i < N/2; i++) // This is the layer | |
for(int j = i; j < N-i-1; j++) { // This is the offset to start | |
// swap | |
int t = matrix[i][j]; | |
matrix[i][j] = matrix[N-j-1][i]; | |
matrix[N-j-1][i] = matrix[N-i-1][N-j-1]; | |
matrix[N-i-1][N-j-1] = matrix[j][N-i-1]; | |
matrix[j][N-i-1] = t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment