Skip to content

Commit 27e4c4c

Browse files
committed
solve: rotate image
1 parent 8dc94c3 commit 27e4c4c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rotate-image/evan.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def rotate(self, matrix: List[List[int]]) -> None:
6+
"""
7+
Do not return anything, modify matrix in-place instead.
8+
"""
9+
n = len(matrix)
10+
11+
# Step 1: Transpose the matrix
12+
for i in range(n):
13+
for j in range(i, n):
14+
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
15+
16+
# Step 2: Reverse each row
17+
for i in range(n):
18+
matrix[i].reverse()

0 commit comments

Comments
 (0)