We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f134cd commit 596556fCopy full SHA for 596556f
rotate-image/TonyKim9401.java
@@ -0,0 +1,19 @@
1
+// TC: O(n^2)
2
+// visit all elements with nested for-loop
3
+// SC: O(1)
4
+// constant space complexity
5
+class Solution {
6
+ public void rotate(int[][] matrix) {
7
+ int n = matrix.length;
8
+
9
+ for (int i = 0; i < (n + 1) / 2; i++) {
10
+ for (int j = 0; j < n / 2; j++) {
11
+ int temp = matrix[n-1-j][i];
12
+ matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
13
+ matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
14
+ matrix[j][n-1-i] = matrix[i][j];
15
+ matrix[i][j] = temp;
16
+ }
17
18
19
+}
0 commit comments