当前位置:网站首页>Leetcode48. Rotate image
Leetcode48. Rotate image
2022-07-04 10:16:00 【JoesonChan】
subject :
Given a n × n Two dimensional matrix representation of an image .
Rotate image clockwise 90 degree .
explain :
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:
Given matrix =
[
[1,2,3],
[4,5,6],
[7,8,9]
],
In situ rotation input matrix , Turn it into :
[
[7,4,1],
[8,5,2],
[9,6,3]
]Example 2:
Given matrix =
[
[ 5, 1, 9,11],
[ 2, 4, 8,10],
[13, 3, 6, 7],
[15,14,12,16]
],
In situ rotation input matrix , Turn it into :
[
[15,13, 2, 5],
[14, 3, 4, 1],
[12, 6, 8, 9],
[16, 7,10,11]
]
// Rotated image
public static int[][] _124_solution(int[][] matrix) {
// First from [0, 0] To [n-1, n-1] Diagonals , Flip
for (int i = 1; i < matrix.length; i++) {
for (int j = 0; j < i; j++) {
swapMatrix(matrix, i, j, j, i);
}
}
// Then cut the line vertically from the middle , Flip each row
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix.length / 2; j++) {
swapMatrix(matrix, i, j, i, matrix.length - 1 - j);
}
}
return matrix;
}
private static void swapMatrix(int[][] matrix, int i, int j, int a, int b) {
int tmp = matrix[i][j];
matrix[i][j] = matrix[a][b];
matrix[a][b] = tmp;
}
边栏推荐
- 品牌连锁店5G/4G无线组网方案
- Kubernetes CNI 插件之Fabric
- Advanced technology management - how to design and follow up the performance of students at different levels
- 对于程序员来说,伤害力度最大的话。。。
- 查看CSDN个人资源下载明细
- Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
- What is devsecops? Definitions, processes, frameworks and best practices for 2022
- 使用 C# 提取 PDF 文件中的所有文字(支持 .NET Core)
- View CSDN personal resource download details
- Devop basic command
猜你喜欢
What are the advantages of automation?

MongoDB数据日期显示相差8小时 原因和解决方案

Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot

Regular expression (I)

Summary of small program performance optimization practice

【Day2】 convolutional-neural-networks

Pcl:: fromrosmsg alarm failed to find match for field 'intensity'
![[FAQ] summary of common causes and solutions of Huawei account service error 907135701](/img/73/c4ee842475f05e2e67297fcac68779.png)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701

Hands on deep learning (44) -- seq2seq principle and Implementation

Kubernetes CNI 插件之Fabric
随机推荐
Velodyne configuration command
Lavel document reading notes -how to use @auth and @guest directives in lavel
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
PHP代码审计3—系统重装漏洞
AUTOSAR from getting started to mastering 100 lectures (106) - SOA in domain controllers
H5 audio tag custom style modification and adding playback control events
C # use smtpclient The sendasync method fails to send mail, and always returns canceled
Fabric of kubernetes CNI plug-in
Hands on deep learning (45) -- bundle search
Qtreeview+ custom model implementation example
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
Deep learning 500 questions
Use C to extract all text in PDF files (support.Net core)
Golang type comparison
什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
Ruby时间格式转换strftime毫秒匹配格式
Kotlin 集合操作汇总
Vanishing numbers
Golang Modules