Skip to content

Commit d24538b

Browse files
committed
solve : rotate image
1 parent 2e7229f commit d24538b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

rotate-image/samthekorean.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# TC : O(n^2)
2+
# SC : O(1)
3+
class Solution:
4+
def rotate(self, matrix: List[List[int]]) -> None:
5+
top, bottom = 0, len(matrix) - 1
6+
7+
while top < bottom:
8+
left, right = top, bottom
9+
for i in range(bottom - top):
10+
topLeft = matrix[top][left + i]
11+
matrix[top][left + i] = matrix[bottom - i][left]
12+
matrix[bottom - i][left] = matrix[bottom][right - i]
13+
matrix[bottom][right - i] = matrix[top + i][right]
14+
matrix[top + i][right] = topLeft
15+
16+
top, bottom = top + 1, bottom - 1

0 commit comments

Comments
 (0)