Skip to content

Commit cadc4c2

Browse files
authored
Merge pull request #50 from masx200/masx200-patch-1
https://leetcode-cn.com/problems/sentence-similarity-iii/
2 parents cd8393f + 9b30271 commit cadc4c2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Step 2. Add the dependency
4949

5050
<summary>展开查看</summary>
5151

52+
https://leetcode-cn.com/problems/sentence-similarity-iii/
53+
5254
https://leetcode.cn/problems/min-max-game/
5355

5456
https://leetcode-cn.com/problems/wiggle-subsequence/

sentence-similarity-iii/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function areSentencesSimilar(sentence1: string, sentence2: string): boolean {
2+
const words1=sentence1.split(" ")
3+
const words2=sentence2.split(" ")
4+
5+
6+
if(words1.length===words2.length)return sentence1===sentence2
7+
8+
9+
while(words1.length&&words2.length&&words1[words1.length-1]===words2[words2.length-1]){
10+
words1.pop()
11+
words2.pop()
12+
}
13+
14+
while(words1.length&&words2.length&&words1[0]===words2[0]){
15+
words1.shift()
16+
words2.shift()
17+
}
18+
19+
20+
if(words1.length===0||words2.length==0)return true
21+
22+
23+
24+
25+
26+
return false
27+
}
28+
export default areSentencesSimilar

0 commit comments

Comments
 (0)