Medium
https://leetcode.com/problems/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.
Example:
1 |
Given input matrix = |
2019.9.1 独立做出来了
方法:
感觉这道题和打印螺旋数组的题有些类似,重点就是搞清坐标变换(我总是搞混…
从四周向中心依次旋转每层,对每个坐标 replace 它四边上的值。
(下图引用自 https://blog.csdn.net/happyaaaaaaaaaaa/article/details/51563752)
1 |
class (object): |
类似题目:
Triangle
Available Captures for Rook
Uncrossed Lines
近期评论