Leetcode # 48. Rotate Image
- 2022.07.05
- LeetCode
https://leetcode.com/problems/rotate-image/
Solution
Time Complexity: O(M)
Space Complexity: O(1)
class Solution: def rotate(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-place instead. """ # Transepose for i in range(len(matrix)): for j in range(i + 1, len(matrix)): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] # Reflect horizontally for j in range(len(matrix) // 2): for i in range(len(matrix)): matrix[i][j], matrix[i][-1 - j] = matrix[i][-1 - j], matrix[i][j]
Last Updated on 2023/08/16 by A1go