Skip to content

Commit e3d0641

Browse files
committed
1813. 句子相似性 III
1 parent c738ffb commit e3d0641

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
|1047|[删除字符串中的所有相邻重复项](https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/)|[JavaScript](./algorithms/remove-all-adjacent-duplicates-in-string.js)|Easy|
175175
|1780|[判断一个数字是否可以表示成三的幂的和](https://leetcode.cn/problems/check-if-number-is-a-sum-of-powers-of-three/)|[JavaScript](./algorithms/check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
176176
|1807|[替换字符串中的括号内容](https://leetcode.cn/problems/evaluate-the-bracket-pairs-of-a-string/)|[JavaScript](./algorithms/evaluate-the-bracket-pairs-of-a-string.js)|Medium|
177+
|1813|[句子相似性 III](https://leetcode.cn/problems/sentence-similarity-iii/)|[JavaScript](./algorithms/sentence-similarity-iii.js)|Medium|
177178
|1832|[判断句子是否为全字母句](https://leetcode.cn/problems/check-if-the-sentence-is-pangram/)|[JavaScript](./algorithms/check-if-the-sentence-is-pangram.js)|Easy|
178179
|1945|[字符串转化后的各位数字之和](https://leetcode.cn/problems/sum-of-digits-of-string-after-convert/)|[JavaScript](./algorithms/sum-of-digits-of-string-after-convert.js)|Easy|
179180
|2032|[至少在两个数组中出现的值](https://leetcode.cn/problems/two-out-of-three/)|[JavaScript](./algorithms/two-out-of-three.js)|Easy|

algorithms/sentence-similarity-iii.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1813. 句子相似性 III
3+
* @param {string} sentence1
4+
* @param {string} sentence2
5+
* @return {boolean}
6+
*/
7+
var areSentencesSimilar = function (sentence1, sentence2) {
8+
sentence1 = sentence1.split(" ");
9+
sentence2 = sentence2.split(" ");
10+
11+
while (sentence1.length && sentence2.length) {
12+
if (sentence1[0] === sentence2[0]) {
13+
sentence1.shift();
14+
sentence2.shift();
15+
} else if (sentence1.at(-1) === sentence2.at(-1)) {
16+
sentence1.pop();
17+
sentence2.pop();
18+
} else {
19+
return false;
20+
}
21+
}
22+
23+
return true;
24+
};

0 commit comments

Comments
 (0)