In-place Python solution


  • 0
    J
    def rotate(self, matrix):        
        n = len(matrix)
        if n%2:
            id = n//2 +1
        else:
            id = n//2
            
        for i in range(n//2):
            for j in range(id):
                matrix[i][j], matrix[n-1-j][i], matrix[n-1-i][n-1-j], matrix[j][n-1-i] = matrix[n-1-j][i], matrix[n-1-i][n-1-j], matrix[j][n-1-i], matrix[i][j],
    

    Accepted solution, how to make this code more elegent? Thank you in advance!


Log in to reply
 

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