Skip to content

Commit 4fd514c

Browse files
authored
Create Rotate Image - Leetcode 48.py
1 parent 8e0da08 commit 4fd514c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Rotate Image - Leetcode 48.py

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

0 commit comments

Comments
 (0)