旋转图像 给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像. 解题 顺时针旋转90度 就是 上下翻转,再主对角对折 public class Solution { /** * @param matrix: A list of lists of integers * @return: Void */ public void rotate(int[][] A) { // write your code here if (A == null || A.length == 0 || A[0].le
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
48. 旋转图像 模拟题,其实挺不喜欢做模拟题的... 其实这题一层一层的转就好了,外层转完里层再转,其实就是可重叠的子问题了. 转的时候呢,一个数一个数的转,一个数带动四个数.如图所示,2这个数应该怎么转: 难点就是如何用坐标表示出来相对位置,写坐标的时候思路一定要清晰啊! class Solution { public void rotate(int[][] matrix) { int n = matrix.length; for (int k = 0; k < n / 2; k++) {