Skip to content

Instantly share code, notes, and snippets.

@Maggie199
Created January 22, 2015 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maggie199/93476ef21c0118e84801 to your computer and use it in GitHub Desktop.
Save Maggie199/93476ef21c0118e84801 to your computer and use it in GitHub Desktop.
Leetcode #48
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