2025-08-16 07:49:39 +0000 UTC
Determine Whether Matrix Can Be Obtained By Rotation
Categories:
Links
Code
class Solution:
def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool:
length = len(mat)
count_0, count_90, count_180, count_270 = 0, 0, 0, 0
for i in range(length):
for j in range(length):
val = mat[i][j]
if val == target[i][j]:
count_0 += 1
if val == target[j][length - i - 1]:
count_90 += 1
if val == target[length - i - 1][length - j - 1]:
count_180 += 1
if val == target[length - j - 1][i]:
count_270 += 1
return length * length in {count_0, count_90, count_180, count_270}