One line python solution


  • 0
    R

    Transpose the matrix, while also reversing every line:

    class Solution:
    # @param matrix, a list of lists of integers
    # @return a list of lists of integers
    def rotate(self, matrix):
        return [[row[i] for row in matrix][::-1] for i in range(len(matrix))]

  • 0
    C

    You should do it in-palce, no return in this case. You can do like: matrix[:] = [[row[i] for row in matrix][::-1] for i in range(len(matrix))]


Log in to reply
 

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