Skip to content

Commit cbea1d4

Browse files
Merge pull request #1991 from CodingTestStudy2/이진희
[이진희] Day08
2 parents 85baba7 + 7869b6c commit cbea1d4

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
3+
1. 아이디어 : mat을 90, 180, 270, 360도로 배열을 회전했을때 target과 일치하면 true, 아니면 false
4+
배열 회전 공식을 사용한다.
5+
6+
2. 시간복잡도 : O(N^2*3)
7+
8+
3. 자료구조/알고리즘 : 완전탐색
9+
10+
*/
11+
12+
class Solution {
13+
public boolean findRotation(int[][] mat, int[][] target) {
14+
15+
boolean check;
16+
int n = mat.length;
17+
18+
// 90도 회전해서 가능하면 true
19+
for(int cnt=0; cnt<4; cnt++) {
20+
if(cnt>0) mat = rotate90(mat, n);
21+
22+
check = true;
23+
for(int i=0; i<n; i++) {
24+
for(int j=0; j<n; j++) {
25+
if(target[i][j] != mat[i][j]) check = false;
26+
}
27+
}
28+
29+
if(check == true) return true;
30+
}
31+
32+
return false;
33+
}
34+
35+
private int[][] rotate90(int[][] mat, int n) {
36+
37+
int[][] rotated = new int[n][n];
38+
39+
for(int i=0; i<n; i++) {
40+
for(int j=0; j<n; j++) {
41+
rotated[j][n-1-i] = mat[i][j];
42+
}
43+
}
44+
45+
return rotated;
46+
}
47+
}

0 commit comments

Comments
 (0)