File tree 3 files changed +94
-0
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder
3 files changed +94
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ Your ideas/fixes/algorithms are more than welcome!
34
34
| 900| [ Sort Array By Parity] ( https://leetcode.com/problems/sort-array-by-parity/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_900.java ) | O(n) | O(1) | | Easy|
35
35
| 896| [ Monotonic Array] ( https://leetcode.com/problems/monotonic-array/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_896.java ) | O(n) | O(1) | | Easy|
36
36
| 884| [ Uncommon Words from Two Sentences] ( https://leetcode.com/problems/uncommon-words-from-two-sentences/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_884.java ) | O(n) | O(k) | | Easy|
37
+ | 867| [ Transpose Matrix] ( https://leetcode.com/problems/transpose-matrix/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_867.java ) | O(r* c) | O(r* c) | | Easy|
37
38
| 852| [ Peak Index in a Mountain Array] ( https://leetcode.com/problems/peak-index-in-a-mountain-array/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_852.java ) | O(n) | O(1) | | Easy|
38
39
| 844| [ Backspace String Compare] ( https://leetcode.com/problems/backspace-string-compare/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_844.java ) | O(n) | O(1) | | Easy|
39
40
| 832| [ Flipping an Image] ( https://leetcode.com/problems/flipping-an-image/ ) | [ Solution] ( ../master/src/main/java/com/fishercoder/solutions/_832.java ) | O(n) | O(1) | | Easy|
Original file line number Diff line number Diff line change
1
+ package com .fishercoder .solutions ;
2
+
3
+ public class _867 {
4
+ public static class Solution1 {
5
+ public int [][] transpose (int [][] A ) {
6
+ int [][] result = new int [A [0 ].length ][A .length ];
7
+ for (int i = 0 ; i < A .length ; i ++) {
8
+ for (int j = 0 ; j < A [0 ].length ; j ++) {
9
+ result [j ][i ] = A [i ][j ];
10
+ }
11
+ }
12
+ return result ;
13
+ }
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package com .fishercoder ;
2
+
3
+ import com .fishercoder .solutions ._867 ;
4
+ import com .fishercoder .solutions ._9 ;
5
+ import org .junit .BeforeClass ;
6
+ import org .junit .Test ;
7
+
8
+ import static org .junit .Assert .assertArrayEquals ;
9
+ import static org .junit .Assert .assertEquals ;
10
+
11
+ public class _867Test {
12
+ private static _867 .Solution1 solution1 ;
13
+ private static int [][] A ;
14
+ private static int [][] result ;
15
+
16
+ @ BeforeClass
17
+ public static void setup () {
18
+ solution1 = new _867 .Solution1 ();
19
+ }
20
+
21
+ @ Test
22
+ public void test1 () {
23
+ A = new int [][]{
24
+ {1 , 2 , 3 },
25
+ {4 , 5 , 6 },
26
+ {7 , 8 , 9 }
27
+ };
28
+ result = new int [][]{
29
+ {1 , 4 , 7 },
30
+ {2 , 5 , 8 },
31
+ {3 , 6 , 9 }
32
+ };
33
+ assertArrayEquals (result , solution1 .transpose (A ));
34
+ }
35
+
36
+ @ Test
37
+ public void test2 () {
38
+ A = new int [][]{
39
+ {1 , 2 , 3 }
40
+ };
41
+ result = new int [][]{
42
+ {1 },
43
+ {2 },
44
+ {3 }
45
+ };
46
+ assertArrayEquals (result , solution1 .transpose (A ));
47
+ }
48
+
49
+ @ Test
50
+ public void test3 () {
51
+ A = new int [][]{
52
+ {1 },
53
+ {2 },
54
+ {3 }
55
+ };
56
+ result = new int [][]{
57
+ {1 , 2 , 3 }
58
+ };
59
+ assertArrayEquals (result , solution1 .transpose (A ));
60
+ }
61
+
62
+ @ Test
63
+ public void test4 () {
64
+ A = new int [][]{
65
+ {1 , 2 , 3 , 4 },
66
+ {5 , 6 , 7 , 8 },
67
+ {9 , 10 , 11 , 12 }
68
+ };
69
+ result = new int [][]{
70
+ {1 , 5 , 9 },
71
+ {2 , 6 , 10 },
72
+ {3 , 7 , 11 },
73
+ {4 , 8 , 12 }
74
+ };
75
+ assertArrayEquals (result , solution1 .transpose (A ));
76
+ }
77
+
78
+ }
You can’t perform that action at this time.
0 commit comments