---
# System prepended metadata

title: Leetcode 48. Rotate Image

---

# Leetcode 48. Rotate Image

## 題解

```python=
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):
            for j in range(i+1,n):
                matrix[i][j],matrix[j][i] = matrix[j][i],matrix[i][j]
        # 每一行顛倒
        for i in range(n):
            matrix[i] = matrix[i][::-1]
```