当前位置:网站首页>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;
}
边栏推荐
- Today's sleep quality record 78 points
- How web pages interact with applets
- 智慧路灯杆水库区安全监测应用
- Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 1
- Hands on deep learning (44) -- seq2seq principle and Implementation
- Uniapp--- initial use of websocket (long link implementation)
- Exercise 7-8 converting strings to decimal integers (15 points)
- 什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
- Pcl:: fromrosmsg alarm failed to find match for field 'intensity'
- 查看CSDN个人资源下载明细
猜你喜欢
xxl-job惊艳的设计,怎能叫人不爱
MATLAB小技巧(25)竞争神经网络与SOM神经网络
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2
Today's sleep quality record 78 points
Hands on deep learning (35) -- text preprocessing (NLP)
C语言指针经典面试题——第一弹
Machine learning -- neural network (IV): BP neural network
Fabric of kubernetes CNI plug-in
智能网关助力提高工业数据采集和利用
【Day1】 deep-learning-basics
随机推荐
Uniapp--- initial use of websocket (long link implementation)
Hands on deep learning (34) -- sequence model
Use the data to tell you where is the most difficult province for the college entrance examination!
What is devsecops? Definitions, processes, frameworks and best practices for 2022
How to teach yourself to learn programming
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
Golang defer
Golang 类型比较
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 1
Basic principle of servlet and application of common API methods
[200 opencv routines] 218 Multi line italic text watermark
The future education examination system cannot answer questions, and there is no response after clicking on the options, and the answers will not be recorded
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
智慧路灯杆水库区安全监测应用
Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
Number of relationship models
IIS configure FTP website
El Table Radio select and hide the select all box
C language pointer classic interview question - the first bullet
Hands on deep learning (38) -- realize RNN from scratch