Back to questions
Given two n x n binary matrices and , return true if it is possible to make equal to by rotating mat in 90-degree increments, or false otherwise.
Input: mat = , target =
Output: true
Explanation: We can rotate mat 180 degrees to go from the input to the
Input: mat = , target =
Output: false
Explanation: It is impossible to make mat equal to target by rotating .
If you have a matrix and you rotate it repeatedly, how many different rotated matrices do you think you will get? It will just be . So, our approach is to get those four different matrices and check if at least one of them matches the target.
Here is the code:
Our current approach creates a new matrix every time we reverse the matrix, but we don't have to do this; we can just rotate the given matrix ().