Determine Whether Matrix Can Be Obtained By Rotation LeetCode solution in JavaScript

1
var findRotation = function (mat, target) {
2
let width = mat[0].length;
3
let height = mat.length;
4

5
let normal = true;
6
let rightOneTime = true;
7
let rightTwoTimes = true;
8
let rightThreeTimes = true;
9
for (let i = 0; i < height; i++) {
10
for (let j = 0; j < width; j++) {
11
// don't rotate mat
12
if (mat[i][j] !== target[i][j]) {
13
normal = false;
14
}
15
// rotate mat right 1 time
16
if (mat[i][j] !== target[j][width - 1 - i]) {
17
rightOneTime = false;
18
}
19
// rotate mat right 2 times
20
if (mat[i][j] !== target[height - 1 - i][width - 1 - j]) {
21
rightTwoTimes = false;
22
}
23
// rotate mat right 3 times
24
if (mat[i][j] !== target[height - 1 - j][i]) {
25
rightThreeTimes = false;
26
}
27
}
28
}
29
return normal || rightOneTime || rightTwoTimes || rightThreeTimes;
30
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0