Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b6ec46

Browse files
add 867
1 parent3684b68 commit8b6ec46

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Your ideas/fixes/algorithms are more than welcome!
3434
|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|
3535
|896|[Monotonic Array](https://leetcode.com/problems/monotonic-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_896.java)| O(n)| O(1)||Easy|
3636
|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|
3738
|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|
3839
|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|
3940
|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|
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_867 {
4+
publicstaticclassSolution1 {
5+
publicint[][]transpose(int[][]A) {
6+
int[][]result =newint[A[0].length][A.length];
7+
for (inti =0;i <A.length;i++) {
8+
for (intj =0;j <A[0].length;j++) {
9+
result[j][i] =A[i][j];
10+
}
11+
}
12+
returnresult;
13+
}
14+
}
15+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._867;
4+
importcom.fishercoder.solutions._9;
5+
importorg.junit.BeforeClass;
6+
importorg.junit.Test;
7+
8+
importstaticorg.junit.Assert.assertArrayEquals;
9+
importstaticorg.junit.Assert.assertEquals;
10+
11+
publicclass_867Test {
12+
privatestatic_867.Solution1solution1;
13+
privatestaticint[][]A;
14+
privatestaticint[][]result;
15+
16+
@BeforeClass
17+
publicstaticvoidsetup() {
18+
solution1 =new_867.Solution1();
19+
}
20+
21+
@Test
22+
publicvoidtest1() {
23+
A =newint[][]{
24+
{1,2,3},
25+
{4,5,6},
26+
{7,8,9}
27+
};
28+
result =newint[][]{
29+
{1,4,7},
30+
{2,5,8},
31+
{3,6,9}
32+
};
33+
assertArrayEquals(result,solution1.transpose(A));
34+
}
35+
36+
@Test
37+
publicvoidtest2() {
38+
A =newint[][]{
39+
{1,2,3}
40+
};
41+
result =newint[][]{
42+
{1},
43+
{2},
44+
{3}
45+
};
46+
assertArrayEquals(result,solution1.transpose(A));
47+
}
48+
49+
@Test
50+
publicvoidtest3() {
51+
A =newint[][]{
52+
{1},
53+
{2},
54+
{3}
55+
};
56+
result =newint[][]{
57+
{1,2,3}
58+
};
59+
assertArrayEquals(result,solution1.transpose(A));
60+
}
61+
62+
@Test
63+
publicvoidtest4() {
64+
A =newint[][]{
65+
{1,2,3,4},
66+
{5,6,7,8},
67+
{9,10,11,12}
68+
};
69+
result =newint[][]{
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+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp