当前位置:网站首页>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;
}
边栏推荐
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
- 【Day2】 convolutional-neural-networks
- Exercise 7-2 finding the maximum value and its subscript (20 points)
- SQL replying to comments
- Deep learning 500 questions
- Work order management system OTRs
- Latex arranges single column table pictures in double column format articles
- Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
- Basic principle of servlet and application of common API methods
- Container cloud notes
猜你喜欢
Debug:==42==ERROR: AddressSanitizer: heap-buffer-overflow on address
Hands on deep learning (34) -- sequence model
Kubernetes CNI 插件之Fabric
【Day2】 convolutional-neural-networks
Application of safety monitoring in zhizhilu Denggan reservoir area
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
Histogram equalization
Hands on deep learning (35) -- text preprocessing (NLP)
Hands on deep learning (40) -- short and long term memory network (LSTM)
品牌连锁店5G/4G无线组网方案
随机推荐
Deep learning 500 questions
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
Does any teacher know how to inherit richsourcefunction custom reading Mysql to do increment?
Golang defer
Hands on deep learning (32) -- fully connected convolutional neural network FCN
浅谈Multus CNI
智慧路灯杆水库区安全监测应用
百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
Advanced technology management - how to design and follow up the performance of students at different levels
[200 opencv routines] 218 Multi line italic text watermark
View CSDN personal resource download details
【Day2】 convolutional-neural-networks
六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽
SQL replying to comments
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Check 15 developer tools of Alibaba
Exercise 7-8 converting strings to decimal integers (15 points)
Vanishing numbers
Laravel文档阅读笔记-How to use @auth and @guest directives in Laravel
Hands on deep learning (37) -- cyclic neural network