File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ Step 2. Add the dependency
49
49
50
50
<summary >展开查看</summary >
51
51
52
+ https://leetcode-cn.com/problems/sentence-similarity-iii/
53
+
52
54
https://leetcode.cn/problems/min-max-game/
53
55
54
56
https://leetcode-cn.com/problems/wiggle-subsequence/
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments