-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate-image.py
29 lines (24 loc) · 1.06 KB
/
rotate-image.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
25
26
27
28
29
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
right = len(matrix) -1
b = 0
# run until leftcolumn is less that right column
while b < right:
# iterate from left to right, x will take care of element in each row
for x in range(right-b):
#store top left elelemt in a temp variable
tmp = matrix[b][b+x]
# move bottom left to top right's location
matrix[b][b+x] = matrix[right-x][b]
# move bottom right to bottom left
matrix[right-x][b] = matrix[right][right-x]
# move top right to bottom right
matrix[right][right-x] = matrix[b+x][right]
#top right becomes the temo which was top left
matrix[b+x][right] = tmp
## update boundaries
b+=1
right-=1