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

Commit6e25d84

Browse files
add 1813
1 parente97d066 commit6e25d84

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-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+
|1813|[Sentence Similarity III](https://leetcode.com/problems/sentence-similarity-iii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1813.java)||Medium|String|
1112
|1812|[Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1812.java)||Easy|String|
1213
|1807|[Evaluate the Bracket Pairs of a String](https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1807.java)||Medium|HashTable, String|
1314
|1806|[Minimum Number of Operations to Reinitialize a Permutation](https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1806.java)||Medium|Array, Greedy|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1813 {
4+
publicstaticclassSolution1 {
5+
publicbooleanareSentencesSimilar(Stringsentence1,Stringsentence2) {
6+
Stringshorter =sentence1.length() <sentence2.length() ?sentence1 :sentence2;
7+
Stringlonger =shorter.equals(sentence1) ?sentence2 :sentence1;
8+
String[]shortWords =shorter.split(" ");
9+
String[]longWords =longer.split(" ");
10+
intbreaks =0;
11+
intj =0;
12+
inti =0;
13+
for (;i <shortWords.length &&j <longWords.length; ) {
14+
if (shortWords[i].equals(longWords[j])) {
15+
j++;
16+
i++;
17+
}else {
18+
breaks++;
19+
if (breaks >1) {
20+
returnfalse;
21+
}
22+
while (j <longWords.length && !longWords[j].equals(shortWords[i])) {
23+
j++;
24+
}
25+
}
26+
}
27+
return (breaks ==1 &&i ==shortWords.length &&j ==longWords.length) || (i ==shortWords.length &&breaks ==0);
28+
}
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1813;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1813Test {
10+
privatestatic_1813.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1813.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(false,solution1.areSentencesSimilar("of","A lot of words"));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(true,solution1.areSentencesSimilar("Eating right now","Eating"));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(true,solution1.areSentencesSimilar("c h p Ny","c BDQ r h p Ny"));
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp