Determine Whether Matrix Can Be Obtained By Rotation LeetCode solution in Python
1class Solution:2def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool:34# if already equal5if target == mat:6return True7# there are 4 different rotation with 90 deg.8# We need to check at most 3 more rotation.9for i in range(3):10# transpose the matrix by swap row and col values.11for j in range(len(mat)):12for k in range(j + 1, len(mat)):13mat[j][k], mat[k][j] = mat[k][j], mat[j][k]14# Reflect the row by reverse it.15mat[j] = mat[j][::-1]16# now the matrix is roteted; check if they're alike.17if target == mat:18return True19return False