3.将上下的行进行反转,然后按主对角线进行对称交换;这这种方法也很容易做到逆时针旋转。 /* *clockwise rotate*first reverse up to down, then swap the symmetry*1 2 3 7 8 9 7 4 1*4 5 6 => 4 5 6 => 8 5 2*7 8 9 1 2 3 9 6 3*/ /**anticlockwise rotate*first reverse left to ...
LeetCode——Rotate Image 1. Question 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...
48. Rotate Image** 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...
* anticlockwise rotate * first reverse left to right, then swap the symmetry * 1 2 3 3 2 1 3 6 9 * 4 5 6 => 6 5 4 => 2 5 8 * 7 8 9 9 8 7 1 4 7 */// Ref: https://leetcode.com/discuss/20589/a-common-method-to-rotate-the-image// test case: [[1,2,3], [4...
【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Rotate Image You are given annxn2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the imagein-place, which means you have to modify the input 2D matrix directly.DO NOTallocate anothe...
然后学习下正确的翻转姿势:https://discuss.leetcode.com/topic/6796/a-common-method-to-rotate-the-image classSolution {public:/** clockwise rotate * first reverse up to down, then swap the symmetry * 1 2 3 7 8 9 7 4 1 * 4 5 6 => 4 5 6 => 8 5 2 ...
*anticlockwise rotate*first reverse left to right, then swap the symmetry*1 2 3 3 2 1 3 6 9*4 5 6 => 6 5 4 => 2 5 8*7 8 9 9 8 7 1 4 7*/ 1matrix[:] = [each[::-1]foreachinmatrix] 3 for i inrange(len(matrix)): ...
[i]);13}14}1516/*17* anticlockwise rotate18* first reverse left to right, then swap the symmetry19* 1 2 3 3 2 1 3 6 920* 4 5 6 => 6 5 4 => 2 5 821* 7 8 9 9 8 7 1 4 722*/23voidanti_rotate(vector<vector<int> > &matrix) {24for(auto vi : matrix) reverse(vi....