当前位置:网站首页>leetcode 48. Rotate Image 旋转图像(Medium)
leetcode 48. Rotate Image 旋转图像(Medium)
2022-08-04 12:40:00 【InfoQ】
一、题目大意


- n == matrix.length == matrix[i].length
- 1 <= n <= 20
- -1000 <= matrix[i][j] <= 1000
二、解题思路
(i, j)
(N-j, i)
(N-i, N-j)
(j, N-i)
三、解题方法
3.1 Java实现
public class Solution {
public void rotate(int[][] matrix) {
// 输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
// 输出:[[7,4,1],[8,5,2],[9,6,3]]
// x表示行 y表示列
/**
* i 0->n/2 0->2
* j i->n-i i->3-i
* 00 01 02 03
* 11 12
* 从上到下 (j,n-i)
* 从右到左
*
* (j,n-i)<-(i,j)
* (i,j)<-(n-j,i)
* (n-j,i)<-(n-i, n-j)
*/
int temp = 0;
int n = matrix.length - 1;
for (int i = 0; i <= n / 2; i++) {
for (int j = i; j < n - i; j++) {
// 0行n列
temp = matrix[j][n - i];
matrix[j][n - i] = matrix[i][j];
matrix[i][j] = matrix[n-j][i];
matrix[n-j][i] = matrix[n-i][n-j];
matrix[n-i][n-j] = temp;
}
}
}
}
四、总结小记
- 2022/8/4 需要总结一下60多天的刷题了
边栏推荐
猜你喜欢
Geoffrey Hinton:深度学习的下一个大事件
技术分享| 小程序实现音视频通话
接入华为游戏防沉迷,点击防沉迷弹窗后游戏闪退
LeetCode Daily Question (858. Mirror Reflection)
Cool and efficient data visualization big screen, it's really not that difficult to do!丨Geek Planet
什么是 DevOps?看这一篇就够了!
干货丨数学规划视角下的分货优化解题思路
酷开科技 × StarRocks:统一 OLAP 分析引擎,全面打造数字化的 OTT 模式
炫酷又高效的数据可视化大屏,做起来真的没那么难!丨极客星球
Why is Luo Zhenyu's A-share dream so difficult to fulfill?
随机推荐
接入华为游戏防沉迷,点击防沉迷弹窗后游戏闪退
Neck modules of the yolo series
rpm安装提示error: XXX: not an rpm package (or package manifest):
yolo系列的head模块
用VbScript控制光驱
炫酷又高效的数据可视化大屏,做起来真的没那么难!丨极客星球
Launcher app prediction
Why is Luo Zhenyu's A-share dream so difficult to fulfill?
Control CD-ROM with VbScript
缓存字符流
动规(16)-并查集基础题——格子游戏
云原生Devops 的实现方法
Linux-Docker-Mysql安装
持续交付(三)Jenkinsfile语法使用介绍
A discussion of integrated circuits
如何治理资源浪费?百度云原生成本优化最佳实践
高手,云集在于REST、gRPC 和 GraphQL之间!
【软考 系统架构设计师】软件架构设计② 软件架构风格
Ceres库运行,模板内报内存冲突问题。(已解决)
MATLAB——图像分块