Rotate Image
You are given an nxn 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).
(顺时针旋转矩阵90度)
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.
Example:
1. 矩阵转置 + 翻转行
为了在不使用额外空间的情况下实现矩阵的顺时针旋转,可将其变化转变为矩阵的转置,然后对每一行进行翻转。具体实现过程如下:
1 | class Solution: |