48. Rotate Image

class Solution:
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        h = len(matrix[0])
        
        # transpose
        for i in range(h):
            for j in range(i, h):
                matrix[j][i], matrix[i][j] = matrix[i][j], matrix[j][i]
            
        
        for i in range(h):
            matrix[i].reverse()
        

Tranpose -> reverse 하면 되는 쉬운

Runtime: 32 ms, faster than 81.59% of Python3 online submissions for Rotate Image.
Memory Usage: 14.3 MB, less than 17.96% of Python3 online submissions for Rotate Image.

좋은 웹페이지 즐겨찾기