#48
Rotate Image
medium· Math & Geometryruns: 0You are given an n x n 2D matrix representing an image. Rotate the image 90 degrees clockwise in place. You must modify the input matrix directly without using an auxiliary 2D matrix.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 285
class Solution:
def rotate(self, matrix: list[list[int]]) -> None:
n = len(matrix)
for i in range(n):
for j in range(i + 1, n):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
for row in matrix:
row.reverse()
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.