-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy path1886.MatrixRotation.java
36 lines (30 loc) · 972 Bytes
/
1886.MatrixRotation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution {
public boolean findRotation(int[][] mat, int[][] target) {
for (int i = 0; i < 4; i++) {
mat = rotate(mat);
if(check(mat,target))
return true;
}
return false;
}
boolean check(int[][] mat, int[][] target){
for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mat.length; j++) {
if(mat[i][j] != target[i][j])
return false;
}
}
return true;
}
int[][] rotate(int[][] mat){
int col = mat.length-1;
int[][] n = new int[col+1][col+1]; //new 2d array with length same as mat
for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mat.length; j++) {
n[j][col] = mat[i][j]; //putting row wise value of mat to column wise places in n
}
col--;
}
return n;
}
}