[LeetCode] Determine Whether Matrix Can Be Obtained By Rotation

1886. Determine Whether Matrix Can Be Obtained By Rotation

Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {
bool res[4]{true,true,true,true};
int n = mat.size();
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) {
if(mat[i][j] != target[i][j]) res[0] = false;
if(mat[i][j] != target[n-j-1][i]) res[1] = false;
if(mat[i][j] != target[n-i-1][n-j-1]) res[2] = false;
if(mat[i][j] != target[j][n-i-1]) res[3] = false;
}
return res[0] or res[1] or res[2] or res[3];
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/03/28/PS/LeetCode/determine-whether-matrix-can-be-obtained-by-rotation/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.