当前位置:网站首页>48. Rotate image
48. Rotate image
2022-04-23 17:33:00 【hequnwang10】
One 、 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]]
Two 、 Problem solving
Flip instead of rotate
class Solution {
public void rotate(int[][] matrix) {
// This problem is to find rules
// First flip the array horizontally , Then flip it according to the main diagonal
int n = matrix.length;
if(matrix == null){
return ;
}
// First flip according to the horizontal line
for(int i = 0;i<n/2;i++){
for(int j = 0;j<n;j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[n-i-1][j];
matrix[n-i-1][j] = temp;
}
}
// Flip in accordance with the main diagonal
for(int i = 0;i<n;i++){
for(int j = 0;j<i;j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
}
}
版权声明
本文为[hequnwang10]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231732009273.html
边栏推荐
- 基于51单片机红外无线通讯仿真
- Further study of data visualization
- matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
- Entity Framework core captures database changes
- 2. Electron's HelloWorld
- [ES6] promise related (event loop, macro / micro task, promise, await / await)
- 239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
- PC电脑使用无线网卡连接上手机热点,为什么不能上网
- Ouvrir des contrats à terme, ouvrir des comptes en nuage ou faire confiance aux logiciels des sociétés à terme?
- Using quartz under. Net core -- operation transfer parameters of [3] operation and trigger
猜你喜欢
Matlab / Simulink simulation of double closed loop DC speed regulation system
[ES6] promise related (event loop, macro / micro task, promise, await / await)
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
Future 用法详解
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
C语言函数详解
. net type transfer
Detailed explanation of C webpai route
Further study of data visualization
. net cross platform principle (Part I)
随机推荐
Promise (IV)
[C#] 彻底搞明白深拷贝
Qt 修改UI没有生效
Model problems of stock in and stock out and inventory system
In ancient Egypt and Greece, what base system was used in mathematics
ASP. Net core reads the configuration file in the class library project
基于51单片机红外无线通讯仿真
开期货,开户云安全还是相信期货公司的软件?
Clickhouse table engine
Shell-sort命令的使用
394. 字符串解码-辅助栈
双指针进阶--leetcode题目--盛最多水的容器
RPC核心概念理解
Future 用法详解
Baidu Map 3D rotation and tilt angle adjustment
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
线性代数感悟之1
JS failed to change all variables and changed to the return method. Finally, the problem was solved
Summary of common SQL statements
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]