File tree 3 files changed +58
-0
lines changed
solution/0500-0599/0539.Minimum Time Difference
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,27 @@ func min(a, b int) int {
144
144
}
145
145
```
146
146
147
+ ### ** TypeScript**
148
+
149
+ ``` ts
150
+ function findMinDifference(timePoints : string []): number {
151
+ const mins = timePoints
152
+ .map (item => Number (item .slice (0 , 2 )) * 60 + Number (item .slice (3 , 5 )))
153
+ .sort ((a , b ) => a - b );
154
+ const n = mins .length ;
155
+ let res = Infinity ;
156
+ for (let i = 0 ; i < n - 1 ; i ++ ) {
157
+ res = Math .min (res , mins [i + 1 ] - mins [i ]);
158
+ }
159
+
160
+ const first = mins [0 ] + 24 * 60 ;
161
+ const last = mins [n - 1 ];
162
+ res = Math .min (res , first - last );
163
+
164
+ return res ;
165
+ }
166
+ ```
167
+
147
168
### ** ...**
148
169
149
170
```
Original file line number Diff line number Diff line change @@ -122,6 +122,27 @@ func min(a, b int) int {
122
122
}
123
123
```
124
124
125
+ ### ** TypeScript**
126
+
127
+ ``` ts
128
+ function findMinDifference(timePoints : string []): number {
129
+ const mins = timePoints
130
+ .map (item => Number (item .slice (0 , 2 )) * 60 + Number (item .slice (3 , 5 )))
131
+ .sort ((a , b ) => a - b );
132
+ const n = mins .length ;
133
+ let res = Infinity ;
134
+ for (let i = 0 ; i < n - 1 ; i ++ ) {
135
+ res = Math .min (res , mins [i + 1 ] - mins [i ]);
136
+ }
137
+
138
+ const first = mins [0 ] + 24 * 60 ;
139
+ const last = mins [n - 1 ];
140
+ res = Math .min (res , first - last );
141
+
142
+ return res ;
143
+ }
144
+ ```
145
+
125
146
### ** ...**
126
147
127
148
```
Original file line number Diff line number Diff line change
1
+ function findMinDifference ( timePoints : string [ ] ) : number {
2
+ const mins = timePoints
3
+ . map ( item => Number ( item . slice ( 0 , 2 ) ) * 60 + Number ( item . slice ( 3 , 5 ) ) )
4
+ . sort ( ( a , b ) => a - b ) ;
5
+ const n = mins . length ;
6
+ let res = Infinity ;
7
+ for ( let i = 0 ; i < n - 1 ; i ++ ) {
8
+ res = Math . min ( res , mins [ i + 1 ] - mins [ i ] ) ;
9
+ }
10
+
11
+ const first = mins [ 0 ] + 24 * 60 ;
12
+ const last = mins [ n - 1 ] ;
13
+ res = Math . min ( res , first - last ) ;
14
+
15
+ return res ;
16
+ }
You can’t perform that action at this time.
0 commit comments