- Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathrotate-image.py
More file actions
Latest commit
24 lines (20 loc) · 725 Bytes
/
Copy pathrotate-image.py
File metadata and controls
24 lines (20 loc) · 725 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
# 48. Rotate Image
# https://leetcode.com/problems/rotate-image/
classSolution:
defrotate(self, matrix: List[List[int]]) ->None:
"""
Do not return anything, modify matrix in-place instead.
"""
self.reflect(matrix)
self.transpose(matrix)
deftranspose(self, matrix: List[List[int]]) ->None:
foriinrange(1, len(matrix)):
forjinrange(i):
matrix[i][j], matrix[j][i] =matrix[j][i], matrix[i][j]
defreflect(self, matrix: List[List[int]]) ->None:
i=0
j=len(matrix) -1
whilei<j:
matrix[i], matrix[j] =matrix[j], matrix[i]
i+=1
j-=1