python solution


  • 0
    R

    def rotate(matrix):
    """
    :type matrix: List[List[int]]
    :rtype: void Do not return anything, modify matrix in-place instead.
    """
    length = len(matrix)

    for i in range(length):
        for j in range(length - i):
            matrix[i][j], matrix[length - 1 - j][length - 1 - i] = \
                matrix[length - 1 - j][length - 1 - i], matrix[i][j]
    for i in range(length // 2):
        matrix[i], matrix[length - 1 - i] = matrix[length - 1 - i], matrix[i]

Log in to reply
 

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