Skip to content

Commit 59429ea

Browse files
committed
[Add] Leetcode > 48. Rotate Image
1 parent 59828da commit 59429ea

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Leetcode/rotate_image.py

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

0 commit comments

Comments
 (0)