Determine Whether Matrix Can Be Obtained By Rotation
def rotate(matrix):
n = len(matrix)
rotated = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
rotated[j][n - 1 - i] = matrix[i][j]
return rotated
def canBeObtainedByRotation(matrixA, matrixB):
if len(matrixA) != len(matrixB) or len(matrixA[0]) != len(matrixB[0]):
return False
for _ in range(4):
if matrixA == matrixB:
return True
matrixA = rotate(matrixA)
return False
class Solution:
def findRotation(self, mat, target):
return canBeObtainedByRotation(mat, target)