Determine whether matrix can be obtained by rotation

October 12, 2022

array-and-hashmap

Problem URL: Determine whether matrix can be obtained by rotation

We will rotate the matrix 4 times and check if it is equal to the target matrix.

class Solution:
    def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool:
        for i in range(4):
            if mat == target: 
                return True
            mat = list(map(lambda a: list(reversed(a)), zip(*mat)))
        return False

Time complexity: O(n^2)
Space complexity: O(n^2)