---
title: "48. Rotate Image"
url: "https://laigary.com/interview/coding/48-rotate-image"
type: "note"
section: "coding"
date: "2023-01-29"
updated: "2023-01-29"
tags: ["Other"]
---

# 48. Rotate Image

[48\. Rotate Image](https://leetcode.com/problems/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 row in range(n//2 + n %2):
            for col in range(n//2):
                tmp = matrix[n-1-col][row]
                matrix[n-1-col][row] = matrix[n-1-row][n-1-col]
                matrix[n-1-row][n-1-col] = matrix[col][n-1-row]
                matrix[col][n-1-row] = matrix[row][col]
                matrix[row][col] = tmp

```
