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;
    }
};
posted @ 2021-06-06 23:28  Dazzling!  阅读(57)  评论(0编辑  收藏  举报