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.

&nbsp;
Example 1:

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.


Example 2:

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.


Example 3:

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.


&nbsp;
Constraints:


	n == mat.length == target.length
	n == mat[i].length == target[i].length
	1 &lt;= n &lt;= 10
	mat[i][j] and target[i][j] are either 0 or 1.


class Solution:
    def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool:
        
        # if already equal
        if target == mat:
            return True
        # there are 4 different rotation with 90 deg. 
        # We need to check at most 3 more rotation.
        for i in range(3):
            # transpose the matrix by swap row and col values.
            for j in range(len(mat)):
                for k in range(j+1, len(mat)):
                    mat[j][k], mat[k][j] = mat[k][j], mat[j][k]
                # Reflect the row by reverse it.
                mat[j] = mat[j][::-1]
            # now the matrix is roteted; check if they're alike.
            if target == mat:
                return True
        return False
class Solution {
    public boolean findRotation(int[][] mat, int[][] target) {
        if (mat == target) return true;
        int n = mat.length;
        int[] res[] = new int[n][n];
        for (int i = 0; i < n; i++) { //clockwise 90
            for (int j = 0; j < n; j++) {
                res[i][j] = mat[n - 1 - j][i];
            }
        }

        int[] res2[] = new int[n][n];
        for (int i = 0; i < n; i++) { //clockwise 180
            for (int j = 0; j < n; j++) {
                res2[i][j] = res[n - 1 - j][i];
            }
        }

        int[] res3[] = new int[n][n];
        for (int i = 0; i < n; i++) { //clockwise 270
            for (int j = 0; j < n; j++) {
                res3[i][j] = res2[n - 1 - j][i];
            }
        }

        //compare to 90,180,270 and itself
        if(Arrays.deepEquals(target, res) || Arrays.deepEquals(target, res2) || Arrays.deepEquals(target, res3) || Arrays.deepEquals(target, mat) ){
            return true;
        }
        return false;
    }
}

// Arrays.deepEquals() use for matrix
class Solution {
public:
    bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {
        int n = mat.size();
        if(mat == target) { // rotation by 0 degree.
            return true;
        }

        int deg = 3; // more rotations with 90, 180, 270 degree's.

        while(deg --) {
            for(int i = 0; i < n; i ++) {
                for(int j = i; j < n; j ++) {
                    swap(mat[i][j], mat[j][i]); // transpose of matrix.
                }
            }
            for(int i = 0; i < n; i ++) {
                reverse(mat[i].begin(),mat[i].end()); // reverse each row.
            }
            if(mat == target) {
                return true;
            }
        }
        return false;
    }
};
var findRotation = function(mat, target) {
    let width = mat[0].length;
    let height = mat.length;
    
    let normal = true;
    let rightOneTime = true;
    let rightTwoTimes = true;
    let rightThreeTimes = true;
    for (let i = 0; i < height; i++)  {
        for (let j = 0; j < width; j++) {
            // don't rotate mat
            if (mat[i][j] !== target[i][j]) {
                normal = false;
            }
            // rotate mat right 1 time
            if (mat[i][j] !== target[j][width - 1 - i]) {
                rightOneTime = false;
            }
            // rotate mat right 2 times
            if (mat[i][j] !== target[height - 1 - i][width - 1 - j]) {
                rightTwoTimes = false;
            }
            // rotate mat right 3 times
            if (mat[i][j] !== target[height - 1 - j][i]) {
                rightThreeTimes = false;
            }
        }
    }
    return normal || rightOneTime || rightTwoTimes || rightThreeTimes;
};
Determine Whether Matrix Can Be Obtained By Rotation