48. Rotate Image

JJ·2020년 12월 25일
0

Algorithms

목록 보기
30/114
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.

0개의 댓글