当前位置:网站首页>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;
}
边栏推荐
- Hands on deep learning (43) -- machine translation and its data construction
- Container cloud notes
- Service developers publish services based on EDAs
- Custom type: structure, enumeration, union
- 【Day2】 convolutional-neural-networks
- Histogram equalization
- Exercise 7-2 finding the maximum value and its subscript (20 points)
- Regular expression (I)
- SQL replying to comments
- 【Day2】 convolutional-neural-networks
猜你喜欢

Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 1

uniapp 处理过去时间对比现在时间的时间差 如刚刚、几分钟前,几小时前,几个月前

PHP代码审计3—系统重装漏洞

Hands on deep learning (33) -- style transfer

Summary of small program performance optimization practice

Machine learning -- neural network (IV): BP neural network

uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示

libmysqlclient. so. 20: cannot open shared object file: No such file or directory

百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼

对于程序员来说,伤害力度最大的话。。。
随机推荐
Network disk installation
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
【OpenCV 例程200篇】218. 多行倾斜文字水印
Latex learning insertion number - list of filled dots, bars, numbers
uniapp---初步使用websocket(长链接实现)
Summary of reasons for web side automation test failure
uniapp 处理过去时间对比现在时间的时间差 如刚刚、几分钟前,几小时前,几个月前
Pcl:: fromrosmsg alarm failed to find match for field 'intensity'
Golang type comparison
Histogram equalization
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Basic principle of servlet and application of common API methods
Container cloud notes
Hands on deep learning (III) -- Torch Operation (sorting out documents in detail)
Kotlin:集合使用
Exercise 7-3 store the numbers in the array in reverse order (20 points)
Matlab tips (25) competitive neural network and SOM neural network
什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Go context basic introduction