-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
36 lines (34 loc) · 957 Bytes
/
Solution.cs
File metadata and controls
36 lines (34 loc) · 957 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
25
26
27
28
29
30
31
32
33
34
35
36
public class Solution {
public bool FindRotation(int[][] mat, int[][] target) {
for(int i = 0;i<4;i++){
Rotate(mat);
if (IsSame(mat, target)) return true;
}
return false;
}
void Rotate(int[][] mat){
int n = mat.Length;
// [x, x, y, x]
// [y, x, x, x]
// [x, x, x, y]
// [x, y, x, x]
for(int i = 0;i<n/2;i++){
for(int j = i;j<n-i-1;j++){
int tmp = mat[i][j];
mat[i][j] = mat[n-1-j][i];
mat[n-1-j][i] = mat[n-1-i][n-1-j];
mat[n-1-i][n-1-j] = mat[j][n-1-i];
mat[j][n-1-i] = tmp;
}
}
}
bool IsSame(int[][] mat, int[][] tar){
int n = mat.Length;
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if (mat[i][j] != tar[i][j]) return false;
}
}
return true;
}
}