Skip to content

Instantly share code, notes, and snippets.

@iamprayush
Created August 20, 2020 06:32
Show Gist options
  • Save iamprayush/3ae43a3b6da2296ba0ffa61334c2af10 to your computer and use it in GitHub Desktop.
Save iamprayush/3ae43a3b6da2296ba0ffa61334c2af10 to your computer and use it in GitHub Desktop.
Rotate Image
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
n = len(matrix)
for i in range(n//2):
l, r = i, n - i - 1
x = 0
for j in range(l, r):
matrix[l][j], matrix[j][r], matrix[r][r - x], matrix[r - x][l] = (
matrix[r - x][l], matrix[l][j], matrix[j][r], matrix[r][r - x])
x += 1
@iamprayush
Copy link
Author

Screenshot from 2020-08-20 12-01-29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment