当前位置:网站首页>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
边栏推荐
- Why do some people say SCM is simple and I have to learn it so hard?
- [ES6] promise related (event loop, macro / micro task, promise, await / await)
- Baidu Map Case - Zoom component, map scale component
- 双指针进阶--leetcode题目--盛最多水的容器
- 239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
- In embedded system, must the program code in flash be moved to ram to run?
- Understanding of RPC core concepts
- Self use learning notes - connectingstring configuration
- 基于51单片机红外无线通讯仿真
- Shell-sort命令的使用
猜你喜欢
C语言函数详解
PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
SiteServer CMS5. 0 Usage Summary
Devexpress GridView add select all columns
基于51单片机红外无线通讯仿真
Deep understanding of control inversion and dependency injection
Collection of common SQL statements
Learning record of uni app dark horse yougou project (Part 2)
Exercise: even sum, threshold segmentation and difference (two basic questions of list object)
常用SQL语句总结
随机推荐
Collection of common SQL statements
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
開期貨,開戶雲安全還是相信期貨公司的軟件?
ClickHouse-表引擎
Excel quickly and automatically fills the contents of a row on a blank cell
Shell-awk命令的使用
Double pointer advanced -- leetcode title -- container with the most water
Webapi + form form upload file
JVM class loading mechanism
Indexes and views in MySQL
Some problems encountered in recent programming 2021 / 9 / 8
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
48. 旋转图像
For the space occupation of the software, please refer to the installation directory
【WPF绑定3】 ListView基础绑定和数据模板绑定
ASP. Net core dependency injection service life cycle
[batch change MySQL table and corresponding codes of fields in the table]
How does matlab draw the curve of known formula and how does excel draw the function curve image?
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
Use of five routing guards