1886. Determine Whether Matrix Can Be Obtained By Rotation
/**
* Problem: LeetCode 1886 - Determine Whether Matrix Can Be Obtained By Rotation
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public boolean findRotation(int[][] mat, int[][] target) {
int n = mat.length;
boolean r0 = true, r90 = true, r180 = true, r270 = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (mat[i][j] != target[i][j]) {
r0 = false;
}
if (mat[i][j] != target[j][n - 1 - i]) {
r90 = false;
}
if (mat[i][j] != target[n - 1 - i][n - 1 - j]) {
r180 = false;
}
if (mat[i][j] != target[n - 1 - j][i]) {
r270 = false;
}
}
}
return r0 || r90 || r180 || r270;
}
}
"""
Problem: LeetCode 1886 - Determine Whether Matrix Can Be Obtained By Rotation
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
class Solution:
def findRotation(self, mat: list[list[int]], target: list[list[int]]) -> bool:
n = len(mat)
r0 = r90 = r180 = r270 = True
for i in range(n):
for j in range(n):
if mat[i][j] != target[i][j]:
r0 = False
if mat[i][j] != target[j][n - 1 - i]:
r90 = False
if mat[i][j] != target[n - 1 - i][n - 1 - j]:
r180 = False
if mat[i][j] != target[n - 1 - j][i]:
r270 = False
return r0 or r90 or r180 or r270
/**
* Problem: LeetCode 1886 - Determine Whether Matrix Can Be Obtained By Rotation
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
#include <vector>
using namespace std;
class Solution {
public:
bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {
int n = mat.size();
bool r0 = true, r90 = true, r180 = true, r270 = true;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (mat[i][j] != target[i][j]) r0 = false;
if (mat[i][j] != target[j][n - 1 - i]) r90 = false;
if (mat[i][j] != target[n - 1 - i][n - 1 - j]) r180 = false;
if (mat[i][j] != target[n - 1 - j][i]) r270 = false;
}
}
return r0 || r90 || r180 || r270;
}
};
/**
* Problem: LeetCode 1886 - Determine Whether Matrix Can Be Obtained By Rotation
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
var findRotation = function(mat, target) {
const n = mat.length;
let r0 = true, r90 = true, r180 = true, r270 = true;
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (mat[i][j] !== target[i][j]) r0 = false;
if (mat[i][j] !== target[j][n - 1 - i]) r90 = false;
if (mat[i][j] !== target[n - 1 - i][n - 1 - j]) r180 = false;
if (mat[i][j] !== target[n - 1 - j][i]) r270 = false;
}
}
return r0 || r90 || r180 || r270;
};