
😎풀이
- 행렬 전치를 위한 헬퍼 함수를 정의한다.
1-1. arr[i][j] = arr[j][i]의 변환을 의미
1-2. 그 후 행을 역순으로 재정렬
- 전체 행렬을 순회하며 동등 비교 역할을 담당할 헬퍼 함수를 정의한다.
- 90도씩 총 4번을 돌려보며 모든 행렬 전치르 통한 동등 비교를 수행한다.
function findRotation(mat: number[][], target: number[][]): boolean {
let rotate = structuredClone(mat)
for(let i = 0; i < 4; i++) {
if(isSameMatrix(rotate, target)) return true
rotate = transpose(rotate)
}
return false
};
function transpose(mat: number[][]) {
const clone = structuredClone(mat)
const n = mat.length
for(let i = 0; i < n; i++) {
for(let j = i + 1; j < n; j++) {
[clone[i][j], clone[j][i]] = [clone[j][i], clone[i][j]]
}
}
for(let i = 0; i < n; i++) {
clone[i] = clone[i].reverse()
}
return clone
}
function isSameMatrix(mat1: number[][], mat2: number[][]) {
for(let i = 0; i < mat1.length; i++) {
for(let j = 0; j < mat1.length; j++) {
if(mat1[i][j] !== mat2[i][j]) return false
}
}
return true
}
늘 잘 보고 있어요 ^^7