Skip to content

Commit c25ac8a

Browse files
committed
[:solved] #281
1 parent 8684a5e commit c25ac8a

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

rotate-image/ppxyn1.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# idea: -
2+
# Time Complexity: O(n^2)
3+
4+
'''
5+
1 2 3
6+
4 5 6
7+
7 8 9
8+
'''
9+
class Solution:
10+
def rotate(self, matrix: List[List[int]]) -> None:
11+
"""
12+
Do not return anything, modify matrix in-place instead.
13+
"""
14+
n = len(matrix)
15+
# Transpose (diagonal elements are fixed)
16+
'''
17+
1 4 7
18+
2 5 8
19+
3 6 9
20+
'''
21+
for i in range(n):
22+
for j in range(i+1,n):
23+
matrix[i][j] , matrix[j][i] = matrix[j][i], matrix[i][j]
24+
25+
# Reverse each row
26+
'''
27+
7 4 1
28+
8 5 2
29+
9 6 3
30+
'''
31+
for r in matrix:
32+
r.reverse()

0 commit comments

Comments
 (0)