Skip to content

Commit 7067abc

Browse files
committed
feat: rotate-image
1 parent 174fec9 commit 7067abc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

rotate-image/minji-go.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* <a href="https://leetcode.com/problems/rotate-image/">week15-4. rotate-image</a>
3+
* <li>Description: Given an n x n 2D matrix representing an image, rotate the image by 90 degrees</li>
4+
* <li>Topics: Array, Math, Matrix</li>
5+
* <li>Time Complexity: O(N²), Runtime 0ms </li>
6+
* <li>Space Complexity: O(1), Memory 42.11MB </li>
7+
*/
8+
9+
class Solution {
10+
public void rotate(int[][] matrix) {
11+
int n = matrix.length;
12+
13+
for (int i = 0; i < n / 2; i++) {
14+
for (int j = i; j < n - 1 - i; j++) {
15+
int temp = matrix[i][j];
16+
matrix[i][j] = matrix[n - 1 - j][i];
17+
matrix[n - 1 - j][i] = matrix[n - 1 - i][n - 1 - j];
18+
matrix[n - 1 - i][n - 1 - j] = matrix[j][n - 1 - i];
19+
matrix[j][n - 1 - i] = temp;
20+
}
21+
}
22+
}
23+
}
24+

0 commit comments

Comments
 (0)