One logical line python solution. Rotate in place.


  • 0
    M

    Rotating from outermost square to innermost square. Rotating one square per outer iteration.

        def rotate(self, matrix):
            """
            :type matrix: List[List[int]]
            :rtype: void Do not return anything, modify matrix in-place instead.
            """
            size=len(matrix)-1
            print matrix
            for i in range(len(matrix)):
                for j in range(i,len(matrix)-i-1):
                    matrix[i][j],matrix[j][size-i],matrix[size-i][size-j],matrix[size-j][i]=matrix[size-j][i],matrix[i][j],matrix[j][size-i],matrix[size-i][size-j]```

Log in to reply
 

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