straightforward python implementation

  • 0
    class Solution(object):
        def rotate(self, matrix):
            :type matrix: List[List[int]]
            :rtype: void Do not return anything, modify matrix in-place instead.
            l = len(matrix)
            if l%2 == 0:
                g = l//2
                g = l//2 + 1
            for i in range(g):
                for j in range(i,l-1-i):
                    a = matrix[i][j]
                    b = matrix[j][l-1-i]
                    c = matrix[l-1-i][l-1-j]
                    d = matrix[l-1-j][i]
                    matrix[i][j] = d
                    matrix[j][l-1-i] = a
                    matrix[l-1-i][l-1-j] = b
                    matrix[l-1-j][i] = c

Log in to reply

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