File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 40
40
41
41
```
42
42
43
+ ### ** TypeScript**
44
+
45
+ ``` ts
46
+ function findClosest(words : string [], word1 : string , word2 : string ): number {
47
+ let index1 = 100000 ;
48
+ let index2 = - 100000 ;
49
+ let res = 100000 ;
50
+ const n = words .length ;
51
+ for (let i = 0 ; i < n ; i ++ ) {
52
+ const word = words [i ];
53
+ if (word === word1 ) {
54
+ index1 = i ;
55
+ } else if (word === word2 ) {
56
+ index2 = i ;
57
+ }
58
+ res = Math .min (res , Math .abs (index1 - index2 ));
59
+ }
60
+ return res ;
61
+ }
62
+ ```
63
+
43
64
### ** ...**
44
65
45
66
```
Original file line number Diff line number Diff line change 36
36
37
37
```
38
38
39
+ ### ** TypeScript**
40
+
41
+ ``` ts
42
+ function findClosest(words : string [], word1 : string , word2 : string ): number {
43
+ let index1 = 100000 ;
44
+ let index2 = - 100000 ;
45
+ let res = 100000 ;
46
+ const n = words .length ;
47
+ for (let i = 0 ; i < n ; i ++ ) {
48
+ const word = words [i ];
49
+ if (word === word1 ) {
50
+ index1 = i ;
51
+ } else if (word === word2 ) {
52
+ index2 = i ;
53
+ }
54
+ res = Math .min (res , Math .abs (index1 - index2 ));
55
+ }
56
+ return res ;
57
+ }
58
+ ```
59
+
39
60
### ** ...**
40
61
41
62
```
Original file line number Diff line number Diff line change
1
+ function findClosest ( words : string [ ] , word1 : string , word2 : string ) : number {
2
+ let index1 = 100000 ;
3
+ let index2 = - 100000 ;
4
+ let res = 100000 ;
5
+ const n = words . length ;
6
+ for ( let i = 0 ; i < n ; i ++ ) {
7
+ const word = words [ i ] ;
8
+ if ( word === word1 ) {
9
+ index1 = i ;
10
+ } else if ( word === word2 ) {
11
+ index2 = i ;
12
+ }
13
+ res = Math . min ( res , Math . abs ( index1 - index2 ) ) ;
14
+ }
15
+ return res ;
16
+ }
You can’t perform that action at this time.
0 commit comments