leetcode48专题

leetcode48.旋转图像(中等)

首先推荐一个网站: http://cplusplus.com/ 这里要了解到的新的语法: matrix[i].swap(matrix[n-i-1]); 数组的第i行和第n-i-1行整行交换auto //申请一块临时的变量内存,然后自动储存变量的关键字。 第一种方法是auto一个临时的数组,然后操作。因为: class Solution {public:void ro

leetcode48~Rotate Image

You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? public class RotateImage {//先旋转最外面一层,再旋转里面的层 注意:四个角的不应该重

LeetCode48旋转图像

思路是沿对角线交换元素,之后沿矩阵中线交换元素 参考链接 🔗:【LeetCode 每日一题】48. 旋转图像 | 手写图解版思路 + 代码讲解-哔哩哔哩】 class Solution {public void rotate(int[][] matrix) {int i=0,j=0;if(matrix==null){return;}int n = matrix.length;// int[][

Leetcode48旋转图像

思路:找规律 方法一、一般辅助数组解法 行列转换,第一行变到第三列,第二行变到第二列,第三行变到第一列 matrix[row][col] = matrix[col][n-row-1] 然后复制回原数组 class Solution {public void rotate(int[][] matrix) {int n = matrix.length;int[][] matrix_new