Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Created March 1, 2015 20:14
Show Gist options
  • Save dmnugent80/e71a25ae7cb562877390 to your computer and use it in GitHub Desktop.
Save dmnugent80/e71a25ae7cb562877390 to your computer and use it in GitHub Desktop.
Rotate Matrix
public class Solution {
public void rotate(int[][] matrix) {
int n = matrix.length-1;
if (n == 0) return;
for (int i = 0; i <= n/2; i++){
for (int j = i; j < n-i; j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[n-j][i];
matrix[n-j][i] = matrix[n-i][n-j];
matrix[n-i][n-j] = matrix[j][n-i];
matrix[j][n-i] = temp;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment