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

Commitd4ba403

Browse files
authored
Added Sentence Similarity III.java
1 parente24c5a6 commitd4ba403

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎Medium/Sentence Similarity III.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
classSolution {
2+
publicbooleanareSentencesSimilar(Stringsentence1,Stringsentence2) {
3+
returnisSimilar(sentence1.split(" "),sentence2.split(" ")) ||isSimilar(sentence2.split(" "),
4+
sentence1.split(" "));
5+
}
6+
7+
privatebooleanisSimilar(String[]matcher,String[]target) {
8+
inttargetStartIdx =0;
9+
intmatcherCurrentIdx =0;
10+
while (targetStartIdx <target.length &&matcherCurrentIdx <matcher.length) {
11+
if (!matcher[matcherCurrentIdx].equals(target[targetStartIdx])) {
12+
break;
13+
}
14+
targetStartIdx++;
15+
matcherCurrentIdx++;
16+
}
17+
if (targetStartIdx ==target.length) {
18+
returntrue;
19+
}
20+
inttargetEndIdx =target.length -1;
21+
matcherCurrentIdx =matcher.length -1;
22+
while (targetEndIdx >=targetStartIdx &&matcherCurrentIdx >=0) {
23+
if (!matcher[matcherCurrentIdx].equals(target[targetEndIdx])) {
24+
returnfalse;
25+
}
26+
targetEndIdx--;
27+
matcherCurrentIdx--;
28+
}
29+
returntargetEndIdx ==targetStartIdx -1;
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp