5776. 判断矩阵经轮转后是否一致
模拟矩阵旋转\(90°\),老套路题了。
class Solution {
public:
int n;
void rotate(vector<vector<int>> &mat)
{
vector<vector<int>> temp(n,vector<int>(n));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
temp[j][n-1-i]=mat[i][j];
mat=temp;
}
bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {
n=mat.size();
for(int i=0;i<4;i++)
{
rotate(mat);
if(mat == target) return true;
}
return false;
}
};

浙公网安备 33010602011771号