@@ -196,6 +196,93 @@ func min(a, b int) int {
196
196
}
197
197
```
198
198
199
+ ### ** TypeScript**
200
+
201
+ ``` ts
202
+ function minimumString(a : string , b : string , c : string ): string {
203
+ const f = (s : string , t : string ): string => {
204
+ if (s .includes (t )) {
205
+ return s ;
206
+ }
207
+ if (t .includes (s )) {
208
+ return t ;
209
+ }
210
+ const m = s .length ;
211
+ const n = t .length ;
212
+ for (let i = Math .min (m , n ); i > 0 ; -- i ) {
213
+ if (s .slice (- i ) === t .slice (0 , i )) {
214
+ return s + t .slice (i );
215
+ }
216
+ }
217
+ return s + t ;
218
+ };
219
+ const s: string [] = [a , b , c ];
220
+ const perm: number [][] = [
221
+ [0 , 1 , 2 ],
222
+ [0 , 2 , 1 ],
223
+ [1 , 0 , 2 ],
224
+ [1 , 2 , 0 ],
225
+ [2 , 0 , 1 ],
226
+ [2 , 1 , 0 ],
227
+ ];
228
+ let ans = ' ' ;
229
+ for (const [i, j, k] of perm ) {
230
+ const t = f (f (s [i ], s [j ]), s [k ]);
231
+ if (
232
+ ans === ' ' ||
233
+ t .length < ans .length ||
234
+ (t .length === ans .length && t < ans )
235
+ ) {
236
+ ans = t ;
237
+ }
238
+ }
239
+ return ans ;
240
+ }
241
+ ```
242
+
243
+ ### ** Rust**
244
+
245
+ ``` rust
246
+ impl Solution {
247
+ fn f (s1 : String , s2 : String ) -> String {
248
+ if s1 . contains (& s2 ) {
249
+ return s1 ;
250
+ }
251
+ if s2 . contains (& s1 ) {
252
+ return s2 ;
253
+ }
254
+ for i in 0 .. s1 . len () {
255
+ let s = & s1 [i .. ];
256
+ if s2 . starts_with (s ) {
257
+ let n = s . len ();
258
+ return s1 + & s2 [n .. ];
259
+ }
260
+ }
261
+ s1 + s2 . as_str ()
262
+ }
263
+
264
+ pub fn minimum_string (a : String , b : String , c : String ) -> String {
265
+ let s = [& a , & b , & c ];
266
+ let perm = [
267
+ [0 , 1 , 2 ],
268
+ [0 , 2 , 1 ],
269
+ [1 , 0 , 2 ],
270
+ [1 , 2 , 0 ],
271
+ [2 , 0 , 1 ],
272
+ [2 , 1 , 0 ],
273
+ ];
274
+ let mut ans = String :: new ();
275
+ for [i , j , k ] in perm . iter () {
276
+ let r = Self :: f (Self :: f (s [* i ]. clone (), s [* j ]. clone ()), s [* k ]. clone ());
277
+ if ans == "" || r . len () < ans . len () || (r . len () == ans . len () && r < ans ) {
278
+ ans = r ;
279
+ }
280
+ }
281
+ ans
282
+ }
283
+ }
284
+ ```
285
+
199
286
### ** ...**
200
287
201
288
```
0 commit comments