Skip to content

Commit b4f785b

Browse files
final anwser
1 parent 36f56d4 commit b4f785b

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

Python/chapter01/1.7 - Rotate Matrix/camilo_soluation_1.7.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99

1010
def rotate_matrix(matrix):
11+
matrix.reverse()# we frist reverse the matrix then we take its transpose
12+
1113
m = len(matrix)
1214
n = len(matrix[0])
1315
for i in range(m):
@@ -16,21 +18,10 @@ def rotate_matrix(matrix):
1618
matrix[i][j] = matrix[j][i]
1719
matrix[j][i] = temp
1820

19-
#flip_it(matrix)
20-
#This give us the transpose of a matrix. Now we need to flip it on its image
21-
"""
22-
def flip_it(matrix):
23-
row = len(matrix)-1
24-
col = len(matrix[0])-1
25-
26-
for i in range(row):
27-
for j in range(col/2):
28-
matrix[i][j],matrix[ i][col - 1 - j] = matrix[ i][col - 1 - j] ,matrix[i][j]
29-
30-
"""
31-
3221

3322
matrix = [[1,2,3],[4,5,6],[7,8,9]]
3423
rotate_matrix(matrix)
35-
#flip_it(matrix)
24+
#[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
25+
26+
3627
print(matrix)

0 commit comments

Comments
 (0)