当前位置:网站首页>Leetcode T48: rotating images
Leetcode T48: rotating images
2022-07-04 14:23:00 【Fan Qianzhi】
Title Description
Given a n × n Two dimensional matrix of matrix Represents an image . Please rotate the image clockwise 90 degree .
You must be there. In situ Rotated image , This means that you need to modify the input two-dimensional matrix directly . Please do not Use another matrix to rotate the image .
Example 1:

Input :matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output :[[7,4,1],[8,5,2],[9,6,3]]
Example 2:

Input :matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output :[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
Tips :
- n == matrix.length == matrix[i].length
- 1 <= n <= 20
- -1000 <= matrix[i][j] <= 1000
Ideas
rotate 90° Equal to first Transposition , Again Mirror symmetry .
Code
public void rotate(int[][] matrix) {
int n = matrix.length;
// Transposition
for(int i = 0; i < n; i++) {
for(int j = 0; j < i; j++) {
int t = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = t;
}
}
// Mirror symmetry
for(int i = 0; i < n; i++) {
for(int j = 0; j < n/2; j++) {
int t = matrix[i][j]; matrix[i][j] = matrix[i][n-1-j]; matrix[i][n-1-j] = t;
}
}
}
边栏推荐
- 测试流程整理(3)
- Ws2818m is packaged in cpc8. It is a special circuit for three channel LED drive control. External IC full-color double signal 5v32 lamp programmable LED lamp with outdoor engineering
- [FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions
- What is the real meaning and purpose of doing things, and what do you really want
- redis 日常笔记
- LiveData
- 失败率高达80%,企业数字化转型路上有哪些挑战?
- ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
- R language uses bwplot function in lattice package to visualize box plot and par Settings parameter custom theme mode
- Ruiji takeout notes
猜你喜欢

flink sql-client.sh 使用教程
![去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]

sharding key type not supported

MATLAB中tiledlayout函数使用

Product identification of intelligent retail cabinet based on paddlex

实时数据仓库

C# wpf 实现截屏框实时截屏功能

Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters

nowcoder重排链表

MySQL之详解索引
随机推荐
Ruiji takeout notes
Test evaluation of software testing
Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
【信息检索】链接分析
92.(cesium篇)cesium楼栋分层
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
Use of tiledlayout function in MATLAB
Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
Understand chisel language thoroughly 07. Chisel Foundation (IV) - bundle and VEC
[MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL
商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
ARouter的使用
LiveData
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
Gorm read / write separation (rotation)
Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
Progress in architecture
Product identification of intelligent retail cabinet based on paddlex
PHP log debugging
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process