We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0cd8a25 commit 24a2c2dCopy full SHA for 24a2c2d
rotate-image/hi-rachel.py
@@ -0,0 +1,28 @@
1
+"""
2
+https://leetcode.com/problems/rotate-image/description/
3
+
4
+TC: O(n^2)
5
+SC: O(1)
6
7
8
+from typing import List
9
10
+class Solution:
11
+ def rotate(self, matrix: List[List[int]]) -> None:
12
+ """
13
+ Do not return anything, modify matrix in-place instead.
14
15
+ top, bottom = 0, len(matrix) - 1
16
17
+ while top < bottom:
18
+ left, right = top, bottom
19
20
+ for i in range(bottom - top):
21
+ topLeft = matrix[top][left + i]
22
+ matrix[top][left + i] = matrix[bottom - i][left]
23
+ matrix[bottom - i][left] = matrix[bottom][right - i]
24
+ matrix[bottom][right - i] = matrix[top + i][right]
25
+ matrix[top + i][right] = topLeft
26
27
+ top, bottom = top + 1, bottom - 1
28
0 commit comments