Direct solution no flipping no folding in Python

  • 0

    Process the matrix circle by circle, no need for flipping or folding.


    def rotate(self, matrix):
        size = len(matrix)
        start = 0
        while start <= size//2-1:
            ns = size-2*start
            for i in range(ns-1):
                x = 0
                y = i
                temp = matrix[x+start][y+start]
                for j in range(3):
                    matrix[x+start][y+start] = matrix[(ns-1-y)+start][x+start]
                    x, y = ns-1-y, x
                matrix[x+start][y+start] = temp
            start += 1


Log in to reply

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