File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments