Skip to content

Commit 2fd3605

Browse files
refactor 48
1 parent 20bda00 commit 2fd3605

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/main/java/com/fishercoder/solutions/_48.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class _48 {
1515
/**Note: this is an n*n matrix, in other words, it's a square, this makes it easier as well.*/
1616

1717
public static class Solution1 {
18+
//Time: O(n^2)
19+
//Space: O(1)
1820
public void rotate(int[][] matrix) {
1921
/**First swap the elements on the diagonal, then reverse each row:
2022
* 1, 2, 3 1, 4, 7 7, 4, 1

src/test/java/com/fishercoder/_48Test.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,26 @@ public void test2() {
3737
solution2.rotate(matrix);
3838
CommonUtils.print2DIntArray(matrix);
3939
}
40+
41+
@Test
42+
public void test3() {
43+
matrix = new int[][]{
44+
{1, 2, 3, 4},
45+
{5, 6, 7, 8},
46+
{9, 10, 11, 12},
47+
{13, 14, 15, 16}
48+
};
49+
solution2.rotate(matrix);
50+
CommonUtils.print2DIntArray(matrix);
51+
}
52+
53+
@Test
54+
public void test4() {
55+
matrix = new int[][]{
56+
{1, 2},
57+
{3, 4}
58+
};
59+
solution1.rotate(matrix);
60+
CommonUtils.print2DIntArray(matrix);
61+
}
4062
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy