Created
January 22, 2015 04:55
-
-
Save Maggie199/93476ef21c0118e84801 to your computer and use it in GitHub Desktop.
Leetcode #48
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) { | |
int len = matrix.length; | |
int start, end, element; | |
for(int layer=0; layer<len/2;layer++){ | |
start = layer; | |
end = len-1-start; | |
for(int gp=0; gp<end-start;gp++){ | |
element = matrix[layer][start+gp]; | |
matrix[layer][start+gp] = matrix[end-gp][layer]; | |
matrix[end-gp][layer] = matrix[len-1-layer][end-gp]; | |
matrix[len-1-layer][end-gp] = matrix[start+gp][len-1-layer]; | |
matrix[start+gp][len-1-layer] = element; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment