File tree 3 files changed +58
-0
lines changed
solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -365,6 +365,27 @@ impl Solution {
365
365
}
366
366
```
367
367
368
+ ### ** C#**
369
+
370
+ ``` cs
371
+ public class Solution {
372
+ public int GarbageCollection (string [] garbage , int [] travel ) {
373
+ int len = garbage .Length ;
374
+ int res = 0 ;
375
+ HashSet < char > s = new HashSet <char >();
376
+ for (int i = len - 1 ; i >= 0 ; i -- ) {
377
+ foreach (char ch in garbage [i ].ToCharArray ()) {
378
+ if (! s .Contains (ch ))
379
+ s .Add (ch );
380
+ }
381
+ res += garbage [i ].Length ;
382
+ res += i > 0 ? s .Count * travel [i - 1 ] : 0 ;
383
+ }
384
+ return res ;
385
+ }
386
+ }
387
+ ```
388
+
368
389
### ** ...**
369
390
370
391
```
Original file line number Diff line number Diff line change @@ -346,6 +346,27 @@ impl Solution {
346
346
}
347
347
```
348
348
349
+ ### ** C#**
350
+
351
+ ``` cs
352
+ public class Solution {
353
+ public int GarbageCollection (string [] garbage , int [] travel ) {
354
+ int len = garbage .Length ;
355
+ int res = 0 ;
356
+ HashSet < char > s = new HashSet <char >();
357
+ for (int i = len - 1 ; i >= 0 ; i -- ) {
358
+ foreach (char ch in garbage [i ].ToCharArray ()) {
359
+ if (! s .Contains (ch ))
360
+ s .Add (ch );
361
+ }
362
+ res += garbage [i ].Length ;
363
+ res += i > 0 ? s .Count * travel [i - 1 ] : 0 ;
364
+ }
365
+ return res ;
366
+ }
367
+ }
368
+ ```
369
+
349
370
### ** ...**
350
371
351
372
```
Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ public int GarbageCollection ( string [ ] garbage , int [ ] travel ) {
3
+ int len = garbage . Length ;
4
+ int res = 0 ;
5
+ HashSet < char > s = new HashSet < char > ( ) ;
6
+ for ( int i = len - 1 ; i >= 0 ; i -- ) {
7
+ foreach ( char ch in garbage [ i ] . ToCharArray ( ) ) {
8
+ if ( ! s . Contains ( ch ) )
9
+ s . Add ( ch ) ;
10
+ }
11
+ res += garbage [ i ] . Length ;
12
+ res += i > 0 ? s . Count * travel [ i - 1 ] : 0 ;
13
+ }
14
+ return res ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments