Rotate Image (Leetcode 48)
Problem Link: https://leetcode.com/problems/rotate-image/
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
n=len(matrix)
# 1) Find the transpose of the matrix
for i in range(n):
for j in range(i):
matrix[i][j],matrix[j][i]=matrix[j][i],matrix[i][j]
# 2) Reverse each row
for i in range(n):
matrix[i]=matrix[i][::-1]
return matrix
Last updated