My simple python solution with O(1) Space


  • 0
    D
    class Solution:
        def rotate(self, matrix):
            """
            :type matrix: List[List[int]]
            :rtype: void Do not return anything, modify matrix in-place instead.
            """
            length = len(matrix)
            tmp = []
            for i in range(0, length // 2):
                for j in range(i, length - i - 1):
                    matrix[i][j],matrix[j][length - i - 1],matrix[length - i - 1][length - j - 1],matrix[length - j - 1][i] = matrix[length - j - 1][i], matrix[i][j], matrix[j][length - i - 1], matrix[length - i - 1][length - j - 1]
                   
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.