Given two n x n
binary matrices mat
and target
, return true
if it is possible to make mat
equal to target
by rotating mat
in 90-degree increments, or false
otherwise.
Input: mat = [[0,1],[1,0]], target = [[1,0],[0,1]] Output: true Explanation: We can rotate mat 90 degrees clockwise to make mat equal target.
Input: mat = [[0,1],[1,1]], target = [[1,0],[0,1]] Output: false Explanation: It is impossible to make mat equal to target by rotating mat.
Input: mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]] Output: true Explanation: We can rotate mat 90 degrees clockwise two times to make mat equal target.
n == mat.length == target.length
n == mat[i].length == target[i].length
1 <= n <= 10
mat[i][j]
andtarget[i][j]
are either0
or1
.
impl Solution {
pub fn find_rotation(mat: Vec<Vec<i32>>, target: Vec<Vec<i32>>) -> bool {
let mut r0 = true;
let mut r1 = true;
let mut r2 = true;
let mut r3 = true;
let n = mat.len();
for r in 0..n {
for c in 0..n {
r0 &= mat[r][c] == target[r][c];
r1 &= mat[r][c] == target[c][n - 1 - r];
r2 &= mat[r][c] == target[n - 1 - r][n - 1 - c];
r3 &= mat[r][c] == target[n - 1 - c][r];
}
}
r0 || r1 || r2 || r3
}
}