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

Commit66bf4b2

Browse files
add 1886
1 parent4c3aff7 commit66bf4b2

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1886|[Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1886.java)||Easy|Array|
1112
|1880|[Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1880.java)||Easy|String|
1213
|1877|[Minimize Maximum Pair Sum in Array](https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1877.java)||Medium|Greedy, Sort|
1314
|1876|[Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1876.java)||Easy|String|
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1886 {
4+
publicstaticclassSolution1 {
5+
publicbooleanfindRotation(int[][]mat,int[][]target) {
6+
intm =mat.length;
7+
intn =mat[0].length;
8+
for (inti =0;i <m;i++) {
9+
intj =0;
10+
for (;j <n;j++) {
11+
if (mat[i][j] !=target[i][j]) {
12+
break;
13+
}
14+
}
15+
if (j <n) {
16+
break;
17+
}elseif (i ==m -1) {
18+
returntrue;
19+
}
20+
}
21+
22+
//rotate 90 degrees once
23+
for (inti =0,k =n -1;i <m;i++,k--) {
24+
intj =0;
25+
for (;j <n;j++) {
26+
if (mat[i][j] !=target[j][k]) {
27+
break;
28+
}
29+
}
30+
if (j <n) {
31+
break;
32+
}elseif (i ==m -1) {
33+
returntrue;
34+
}
35+
}
36+
int[][]rotated =newint[m][n];
37+
for (inti =0,k =n -1;i <m;i++,k--) {
38+
for (intj =0;j <n;j++) {
39+
rotated[j][k] =mat[i][j];
40+
}
41+
}
42+
43+
//rotate 90 degrees the second time
44+
for (inti =0,k =n -1;i <m;i++,k--) {
45+
intj =0;
46+
for (;j <n;j++) {
47+
if (rotated[i][j] !=target[j][k]) {
48+
break;
49+
}
50+
}
51+
if (j <n) {
52+
break;
53+
}elseif (i ==m -1) {
54+
returntrue;
55+
}
56+
}
57+
int[][]rotated2 =newint[m][n];
58+
for (inti =0,k =n -1;i <m;i++,k--) {
59+
intj =0;
60+
for (;j <n;j++) {
61+
rotated2[j][k] =rotated[i][j];
62+
}
63+
}
64+
65+
//rotate 90 degrees the third time
66+
for (inti =0,k =n -1;i <m;i++,k--) {
67+
intj =0;
68+
for (;j <n;j++) {
69+
if (rotated2[i][j] !=target[j][k]) {
70+
break;
71+
}
72+
}
73+
if (j <n) {
74+
break;
75+
}elseif (i ==m -1) {
76+
returntrue;
77+
}
78+
}
79+
returnfalse;
80+
}
81+
}
82+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1886;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1886Test {
10+
privatestatic_1886.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1886.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(true,solution1.findRotation(newint[][]{
20+
{0,1},
21+
{1,0}
22+
},newint[][]{
23+
{1,0},
24+
{0,1}
25+
}));
26+
}
27+
28+
@Test
29+
publicvoidtest2() {
30+
assertEquals(false,solution1.findRotation(newint[][]{
31+
{0,1},
32+
{1,1}
33+
},newint[][]{
34+
{1,0},
35+
{0,1}
36+
}));
37+
}
38+
39+
@Test
40+
publicvoidtest3() {
41+
assertEquals(true,solution1.findRotation(newint[][]{
42+
{0,0,0},
43+
{0,1,0},
44+
{1,1,1}
45+
},newint[][]{
46+
{1,1,1},
47+
{0,1,0},
48+
{0,0,0}
49+
}));
50+
}
51+
52+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp