2024/9/07 LeetCode Hot100 matrix
This commit is contained in:
parent
2236bdab89
commit
92cb0cae5a
|
@ -0,0 +1,36 @@
|
|||
package com.cool.hot100.matrix;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/09/08/0:03
|
||||
* DayNumber 2
|
||||
* Hard 2
|
||||
* Level 5
|
||||
*/
|
||||
public class Num48 {
|
||||
|
||||
public void rotate(int[][] matrix) {
|
||||
int len = matrix.length;
|
||||
if (len==0) {
|
||||
return;
|
||||
}
|
||||
int temp;
|
||||
int level = 0; // 层级
|
||||
int maxLevel = len / 2;
|
||||
// 第n行去第len-1-i列
|
||||
//第n列去第n行
|
||||
while (level < maxLevel) {
|
||||
for(int i=level;i<len-level-1;i++){
|
||||
temp=matrix[level][i];
|
||||
matrix[level][i]=matrix[len-1-i][level];
|
||||
matrix[len-1-i][level]=matrix[len-1-level][len-1-i];
|
||||
matrix[len-1-level][len-1-i]=matrix[i][len-1-level];
|
||||
matrix[i][len-1-level]=temp;
|
||||
}
|
||||
level++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue