当前位置:网站首页>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多天的刷题了
边栏推荐
猜你喜欢

Analysis and comparison of mobile cross-end technical solutions

MATLAB——图像分块

持续交付(四)Jenkins多线程任务执行

酷开科技 × StarRocks:统一 OLAP 分析引擎,全面打造数字化的 OTT 模式

视觉SLAM十四讲学习笔记 第7讲 视觉里程计

Practical sharing of distributed link tracking Jaeger + microservice Pig on Rainbond

情人节浪漫3D照片墙【附源码】

七夕疯狂搞钱的年轻人,一周赚14万

"Lonely Walking on the Moon" is a powerful medicine, it can't cure the internal friction of happy twist

yolo系列的head模块
随机推荐
他是“中台”之父,凭一个概念为阿里狂赚百亿
A comprehensive understanding of MOS tubes, an article is enough
Programmer Qixi Gift - How to quickly build an exclusive chat room for your girlfriend in 30 minutes
高手,云集在于REST、gRPC 和 GraphQL之间!
“蔚来杯“2022牛客暑期多校训练营3 C
"Lonely Walking on the Moon" is a powerful medicine, it can't cure the internal friction of happy twist
Neck modules of the yolo series
动规(16)-并查集基础题——格子游戏
技术分享| 小程序实现音视频通话
七夕疯狂搞钱的年轻人,一周赚14万
从零开始配置 vim(7)——自动命令
广告电商系统开发
break与continue超详解!!!
双目立体视觉笔记(三)三角测量、极线校正
项目里的各种配置,你都了解吗?
推荐一款优秀的通用管理后台
持续交付(三)Jenkinsfile语法使用介绍
Geoffrey Hinton:深度学习的下一个大事件
【VSCode】一文详解vscode下安装vim后无法使用Ctrl+CV复制粘贴 使用Vim插件的配置记录
Focusing on data sources, data quality and model performance to build a credit profile of small and micro enterprises