-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0048-rotate-image.py
More file actions
36 lines (27 loc) · 980 Bytes
/
Copy path0048-rotate-image.py
File metadata and controls
36 lines (27 loc) · 980 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
25
26
27
28
29
30
31
32
33
34
35
36
# https://leetcode.com/problems/rotate-image/
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
# col,2-row
# 0,0 -> 0,2
# 0,2 -> 2,2
# 2,2 -> 2,0
# 2,0 -> 0,0
# 0,1 -> 1,2
# 1,2 -> 2,1
# 2,1 -> 1,0
# 1,0 -> 0,1
num = 0
leng = len(matrix[0])-1
# Going by outter shell by shell
for j in range(len(matrix[0])//2):
# Rotating the elements in first row without last element
for i in range(j,leng-j):
# Swapping corners in 90 deg
row,col=j,i
matrix[col][leng-row],num=matrix[row][col],matrix[col][leng-row]
for i in range(3):
row,col = col,leng-row
matrix[col][leng-row],num = num,matrix[col][leng-row]