当前位置:网站首页>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;
}
}
}
边栏推荐
- What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
- Leetcode 61: 旋转链表
- MySQL的触发器
- Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
- 【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
- gin集成支付宝支付
- Vscode common plug-ins summary
- R language uses bwplot function in lattice package to visualize box plot and par Settings parameter custom theme mode
- Product identification of intelligent retail cabinet based on paddlex
- 2022游戏出海实用发行策略
猜你喜欢

gin集成支付宝支付

leetcode:6109. 知道秘密的人数【dp的定义】

Introducing testfixture into unittest framework

Leetcode 61: 旋转链表

迅为IMX6Q开发板QT系统移植tinyplay

RK1126平台OSD的实现支持颜色半透明度多通道支持中文

Use of tiledlayout function in MATLAB
![[FAQ] summary of common causes and solutions of Huawei account service error 907135701](/img/43/1a9786c89a5ab21d1fb8903cb7b77e.png)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701

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

leetcode:6110. 网格图中递增路径的数目【dfs + cache】
随机推荐
Unity shader learning (3) try to draw a circle
TestSuite and testrunner in unittest
递增的三元子序列[贪心训练]
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
Install MySQL
AI与生命科学
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
Intelligence d'affaires bi analyse financière, analyse financière au sens étroit et analyse financière au sens large sont - ils différents?
Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
The game goes to sea and operates globally
Learning projects are self-made, and growth opportunities are self created
Common content type correspondence table
统计php程序运行时间及设置PHP最长运行时间
Chapter 17 process memory
架构方面的进步
测试流程整理(3)
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
R language uses dplyr package group_ The by function and the summarize function calculate the mean and standard deviation of the target variables based on the grouped variables
AI and Life Sciences