title: 1886. Determine Whether Matrix Can Be Obtained By Rotation
categories: leetcode
comments: false
class 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;
}
};
- time complexity
O(n^2)
- space complexity
O(1)