每日一题 2019 - 03 - 30
题目:
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 NOTallocate another 2D matrix and do the rotation.
Example 1:
1 | Given input matrix = |
Example 2:
1 | Given input matrix = |
解答:
这道题让我们实现矩阵的顺时针旋转90°,可以根据矩阵的性质来进行题解,也即先对矩阵进行转置,随后对转置后的矩阵进行关于垂直对称轴的交换,即可求得相应的结果。
代码:
1 | class Solution { |