Skip to content

Commit 36f56d4

Browse files
My attemp to this soultion
1 parent eb0d432 commit 36f56d4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Rotate Matrix: Given an image represented by an NxN matrix, where each pixel
3+
in the image is 4 bytes, write a method to rotate the image by 90 degrees.
4+
Can you do this in place?
5+
Hints:#51, #100
6+
7+
"""
8+
9+
10+
def rotate_matrix(matrix):
11+
m = len(matrix)
12+
n = len(matrix[0])
13+
for i in range(m):
14+
for j in range(i+1,n):
15+
temp = matrix[i][j]
16+
matrix[i][j] = matrix[j][i]
17+
matrix[j][i] = temp
18+
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+
32+
33+
matrix = [[1,2,3],[4,5,6],[7,8,9]]
34+
rotate_matrix(matrix)
35+
#flip_it(matrix)
36+
print(matrix)

0 commit comments

Comments
 (0)