File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 174
174
| 1047| [ 删除字符串中的所有相邻重复项] ( https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/ ) | [ JavaScript] ( ./algorithms/remove-all-adjacent-duplicates-in-string.js ) | Easy|
175
175
| 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|
176
176
| 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|
177
178
| 1832| [ 判断句子是否为全字母句] ( https://leetcode.cn/problems/check-if-the-sentence-is-pangram/ ) | [ JavaScript] ( ./algorithms/check-if-the-sentence-is-pangram.js ) | Easy|
178
179
| 1945| [ 字符串转化后的各位数字之和] ( https://leetcode.cn/problems/sum-of-digits-of-string-after-convert/ ) | [ JavaScript] ( ./algorithms/sum-of-digits-of-string-after-convert.js ) | Easy|
179
180
| 2032| [ 至少在两个数组中出现的值] ( https://leetcode.cn/problems/two-out-of-three/ ) | [ JavaScript] ( ./algorithms/two-out-of-three.js ) | Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments