Description

You are given an n x n 2D matrix representing an image, rotate the image by 180 degrees (clockwise). You have to rotate the image in-place.

Examples

Input:matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output:[[9,8,7],[6,5,4],[3,2,1]]
Explanation:

180 degree rotation.

Input:matrix = [[1]]
Output:[1]
Explanation:

Minimal case with a single-element matrix.

Input:matrix = [[5,10],[15,20]]
Output:[[20,15],[10,5]]
Explanation:

For a 2x2 matrix, rotating 180 degrees swaps the top-left with bottom-right, and top-right with bottom-left. Element at position (0,0) moves to (1,1), element at (0,1) moves to (1,0), element at (1,0) moves to (0,1), and element at (1,1) moves to (0,0).

Constraints

  • n == matrix.length == matrix[i].length
  • 1 ≤ n ≤ 20

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!