当前位置:网站首页>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
边栏推荐
- C# Task. Delay and thread The difference between sleep
- JS to find the character that appears three times in the string
- 双闭环直流调速系统matlab/simulink仿真
- How to manually implement the mechanism of triggering garbage collection in node
- 198. 打家劫舍-动态规划
- Use of todesk remote control software
- C语言函数详解
- 古代埃及希腊,数学用的什么进制
- 2.Electron之HelloWorld
- 958. 二叉树的完全性检验
猜你喜欢
随机推荐
How does matlab draw the curve of known formula and how does excel draw the function curve image?
剑指 Offer 22. 链表中倒数第k个节点-快慢指针
102. 二叉树的层序遍历
Compare the performance of query based on the number of paging data that meet the query conditions
El date picker limits the selection range from the current time to two months ago
Understanding of RPC core concepts
ECMAScript history
Summary of common SQL statements
超分之TDAN
索引:手把手教你索引从零基础到精通使用
Why do some people say SCM is simple and I have to learn it so hard?
470. 用 Rand7() 实现 Rand10()
Further study of data visualization
[batch change MySQL table and corresponding codes of fields in the table]
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
Advantages and disadvantages of several note taking software
1217_使用SCons生成目标文件
ASP. Net core configuration options (Part 1)
Baidu Map 3D rotation and tilt angle adjustment
[WPF binding 3] listview basic binding and data template binding







![[WPF binding 3] listview basic binding and data template binding](/img/2e/fbdb4175297bb4964a8ccfd0b909ae.png)
