1886. Determine Whether Matrix Can Be Obtained By Rotation 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617181920class Solution {public: bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) { int t =3; int n = mat.size(); if(mat == target) return true; while(t--){ // rotate one time reverse(mat.begin(), mat.end()); for(int i=0;i<n;++i){ for(int j=i+1;j<n;++j){ swap(mat[i][j], mat[j][i]); } } if(mat == target) return true; } return false; }}; analysis time complexity O(n^2) space complexity O(1)