当前位置:网站首页>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;
}
}
}
边栏推荐
- 92.(cesium篇)cesium楼栋分层
- Detailed index of MySQL
- TestSuite and testrunner in unittest
- 商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
- 失败率高达80%,企业数字化转型路上有哪些挑战?
- Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
- R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
- Blob, text geometry or JSON column'xxx'can't have a default value query question
- ViewModel 初体验
- 第十六章 字符串本地化和消息字典(二)
猜你喜欢
失败率高达80%,企业数字化转型路上有哪些挑战?
富文本编辑:wangEditor使用教程
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
leetcode:6110. 网格图中递增路径的数目【dfs + cache】
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
C# wpf 实现截屏框实时截屏功能
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
使用CLion编译OGLPG-9th-Edition源码
随机推荐
Innovation and development of independent industrial software
【云原生】我怎么会和这个数据库杠上了?
PHP log debugging
C # WPF realizes the real-time screen capture function of screen capture box
ViewModel 初体验
Real time data warehouse
Some problems and ideas of data embedding point
Mongodb commonly used 28 query statements (forward)
Chapter 17 process memory
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
Visual Studio调试方式详解
Unity shader learning (3) try to draw a circle
去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]
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
Matters needing attention in overseas game Investment Agency
AI与生命科学
Abnormal value detection using shap value
Leetcode T48:旋转图像
Data warehouse interview question preparation
潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)