Skip to content

Files

Latest commit

1be7fa2 · Oct 10, 2022

History

History

48-RotateImage

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 10, 2022
Oct 10, 2022

Rotate Image

Problem can be found in here!

def rotate(self, matrix: List[List[int]]) -> None:
    def transpose():
        for row in range(n):
            for col in range(row+1, n):
                matrix[row][col], matrix[col][row] = matrix[col][row], matrix[row][col]

    def reflect():
        for row in range(n):
            for col in range(n // 2):
                matrix[row][col], matrix[row][-col-1] = matrix[row][-col-1], matrix[row][col]

    n = len(matrix)
    transpose()
    reflect()
    return

Time Complexity: O(n), Space Complexity: O(1)