- Notifications
You must be signed in to change notification settings - Fork 625
/
Copy path48.py
24 lines (22 loc) · 665 Bytes
/
48.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'''
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
'''
classSolution(object):
defrotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
n=len(matrix)
ifn%2==0:
m=n/2
else:
m=n/2+1
foriinrange(n/2):
forjinrange(m):
temp=matrix[i][j]
matrix[i][j] =matrix[n-j-1][i]
matrix[n-j-1][i] =matrix[n-i-1][n-j-1]
matrix[n-i-1][n-j-1] =matrix[j][n-i-1]
matrix[j][n-i-1] =temp