1. Code
class Solution:
def rotate(self, matrix: list) -> None:
l = len(matrix)-1
for i in range(len(matrix)//2): # the number of edges
for j in range(i, len(matrix[0])-i-1): # the number of times an array must be rotated from that edge
# the rotating elements change continuously
temp = matrix[i][j]
matrix[i][j] = matrix[l-j][i]
matrix[l-j][i] = matrix[l-i][l-j]
matrix[l-i][l-j] = matrix[j][l-i]
matrix[j][l-i] = temp
2. Result
Runtime : 28 ms(96.02%), Memory usage : 14.1 MB(96.08%)
(Runtime can be different by a system even if it is a same code.)