# 48. Rotate Image

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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adit0503.gitbook.io/leetcode/48.-rotate-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
