-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateImage.java
More file actions
24 lines (24 loc) · 854 Bytes
/
RotateImage.java
File metadata and controls
24 lines (24 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public void rotate(int[][] matrix) {
flip(transpose(matrix));
}
private int[][] transpose(int[][] matrix){ // Calculatting transpose of matrix
for(int i=0;i< matrix.length;i++){
for(int j=i+1;j< matrix[i].length;j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
return matrix;
}
private void flip(int[][] matrix){ // Fliping the matrix horizontly
for(int i=0;i< matrix.length;i++){
for(int j=0; j< matrix[i].length/2; j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[i][matrix[i].length-j-1];
matrix[i][matrix[i].length-j-1] = temp;
}
}
}
}