-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateImage.py
More file actions
33 lines (26 loc) · 951 Bytes
/
RotateImage.py
File metadata and controls
33 lines (26 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: None Do not return anything, modify matrix in-place instead.
"""
#column = len(matrix[0])
#row = len(matrix)
#result = []
#col = [matrix[i][1] for i in range(len(matrix))]
'''for j in range(column):
col = []
for i in range(row):
col.append(matrix[i][j])
result.append(col[::-1])'''
n = len(matrix)
# Step 1: Transpose (swap rows and columns)
for i in range(n):
for j in range(i + 1, n):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
print(matrix)
# Step 2: Reverse each row
for i in range(n):
#matrix[i] = complete row
#matrix[i][::-1] = complete row flipper over.
matrix[i] = matrix[i][::-1]