Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6821a29

Browse files
feat: add cs solution to lc problem: No.2391 (doocs#1990)
1 parent 8dcad76 commit 6821a29

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

‎solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,27 @@ impl Solution {
365365
}
366366
```
367367

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+
368389
### **...**
369390

370391
```

‎solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,27 @@ impl Solution {
346346
}
347347
```
348348

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+
349370
### **...**
350371

351372
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /