48. Rotate Image
Medium
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
😇 Solution
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
a = matrix
n = len(a)
for i in range(n):
for j in range(n):
if(i<j):
a[i][j],a[j][i] = a[j][i],a[i][j]
for a1 in a:
a1.reverse()
Last updated
Was this helpful?