> For the complete documentation index, see [llms.txt](https://adit0503.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adit0503.gitbook.io/leetcode/48.-rotate-image.md).

# 48. Rotate Image

Medium

You are given an *n* x *n* 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).\
**Note:** \
You have to rotate the image **in-place**, which means you have to modify the input 2D matrix directly. **DO NOT** allocate another 2D matrix and do the rotation.

## :innocent: [Solution](https://leetcode.com/problems/rotate-image/)

{% tabs %}
{% tab title="O(mn)" %}

```python
class Solution:
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        a = matrix
        n = len(a)
        for i in range(n):
            for j in range(n):
                if(i<j):
                    a[i][j],a[j][i] = a[j][i],a[i][j]
        for a1 in a:
            a1.reverse()
                
```

{% endtab %}
{% endtabs %}
