-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path48.py
More file actions
20 lines (17 loc) · 743 Bytes
/
48.py
File metadata and controls
20 lines (17 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Runtime: 36 ms, faster than 99.51% of Python3 online submissions for Rotate Image.
# Difficulty: Medium
class Solution:
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
length = len(matrix)
#transpose
for row in range(length):
for col in range(row + 1, length):
matrix[row][col], matrix[col][row] = matrix[col][row], matrix[row][col]
#flip horizontal
for row in range(length // 2):
for col in range(length):
matrix[col][row], matrix[col][length-1-row] = matrix[col][length-1-row], matrix[col][row]