给定一个 n × n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。

输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
输出:[[7,4,1],[8,5,2],[9,6,3]

                             
class Solution {
public void rotate(int[][] matrix) {
int len = matrix.length;
//上下交换
for(int i = 0; i < len / 2; i++){ for(int j = 0; j < len; j++){ int temp = matrix[i][j]; matrix[i][j] = matrix[len - 1 - i][j]; matrix[len - 1 - i][j] = temp; } } //以[

给定一个 n × n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。最先出现在Python成神之路

版权声明:
作者:ht
链接:https://www.techfm.club/p/5211.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>