File tree Expand file tree Collapse file tree 2 files changed +21
-26
lines changed
count-nice-pairs-in-an-array Expand file tree Collapse file tree 2 files changed +21
-26
lines changed Original file line number Diff line number Diff line change 1
1
function countNicePairs ( nums : number [ ] ) : number {
2
-
3
- const MOD = 1000000007 ;
2
+ const MOD = 1000000007 ;
4
3
let res = 0 ;
5
- const h = new Map < number , number > ( ) ;
4
+ const h = new Map < number , number > ( ) ;
6
5
for ( const i of nums ) {
7
6
let temp = i , j = 0 ;
8
7
while ( temp > 0 ) {
@@ -13,5 +12,5 @@ function countNicePairs(nums: number[]): number {
13
12
h . set ( i - j , ( h . get ( i - j ) || 0 ) + 1 ) ;
14
13
}
15
14
return res ;
16
- } ;
17
- export default countNicePairs
15
+ }
16
+ export default countNicePairs ;
Original file line number Diff line number Diff line change 1
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
2
+ const words1 = sentence1 . split ( " " ) ;
3
+ const words2 = sentence2 . split ( " " ) ;
21
4
5
+ if ( words1 . length === words2 . length ) return sentence1 === sentence2 ;
22
6
7
+ while (
8
+ words1 . length && words2 . length &&
9
+ words1 [ words1 . length - 1 ] === words2 [ words2 . length - 1 ]
10
+ ) {
11
+ words1 . pop ( ) ;
12
+ words2 . pop ( ) ;
13
+ }
23
14
15
+ while ( words1 . length && words2 . length && words1 [ 0 ] === words2 [ 0 ] ) {
16
+ words1 . shift ( ) ;
17
+ words2 . shift ( ) ;
18
+ }
24
19
20
+ if ( words1 . length === 0 || words2 . length == 0 ) return true ;
25
21
26
- return false
22
+ return false ;
27
23
}
28
- export default areSentencesSimilar
24
+ export default areSentencesSimilar ;
You can’t perform that action at this time.
0 commit comments