当前位置:网站首页>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;
}
边栏推荐
- Latex error: missing delimiter (. Inserted) {\xi \left( {p,{p_q}} \right)} \right|}}
- Golang Modules
- Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
- C language pointer interview question - the second bullet
- 【Day1】 deep-learning-basics
- 基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2
- The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago
- Exercise 9-4 finding books (20 points)
- Advanced technology management - how to design and follow up the performance of students at different levels
- H5 audio tag custom style modification and adding playback control events
猜你喜欢

How can people not love the amazing design of XXL job

The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago

Hands on deep learning (32) -- fully connected convolutional neural network FCN

Pcl:: fromrosmsg alarm failed to find match for field 'intensity'

品牌连锁店5G/4G无线组网方案

Qtreeview+ custom model implementation example

How web pages interact with applets

Custom type: structure, enumeration, union

六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽

Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
随机推荐
C语言指针面试题——第二弹
Modules golang
C # use gdi+ to add text with center rotation (arbitrary angle)
Hands on deep learning (33) -- style transfer
Hands on deep learning (42) -- bi-directional recurrent neural network (BI RNN)
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Latex insert picture, insert formula
用数据告诉你高考最难的省份是哪里!
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
【Day2】 convolutional-neural-networks
leetcode1-3
What is devsecops? Definitions, processes, frameworks and best practices for 2022
Ruby time format conversion strftime MS matching format
Kotlin 集合操作汇总
Normal vector point cloud rotation
Exercise 7-4 find out the elements that are not common to two arrays (20 points)
Work order management system OTRs
Reasons and solutions for the 8-hour difference in mongodb data date display
Use C to extract all text in PDF files (support.Net core)
Kotlin: collection use