Created
February 16, 2020 02:04
-
-
Save wushbin/2c3e83027cfc0c756466755f1f940f98 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
class Solution { | |
public void rotate(int[][] matrix) { | |
trans(matrix); | |
flip(matrix); | |
} | |
private void trans(int[][] matrix) { | |
int row = matrix.length; | |
int col = matrix[0].length; | |
for (int i = 0; i < row; i++) { | |
for (int j = i + 1; j < col; j++) { | |
int tmp = matrix[i][j]; | |
matrix[i][j] = matrix[j][i]; | |
matrix[j][i] = tmp; | |
} | |
} | |
} | |
private void flip(int[][] matrix) { | |
int row = matrix.length; | |
int col = matrix[0].length; | |
for (int i = 0; i < row; i++) { | |
for (int j = 0; j < col / 2; j++) { | |
int tmp = matrix[i][j]; | |
matrix[i][j] = matrix[i][ col - 1 - j]; | |
matrix[i][col - 1 - j] = tmp; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment