Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cs solution to lc problem: No.2391 #1990

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add cs solution to lc problem: No.2391
  • Loading branch information
dev-mauli authored Nov 20, 2023
commit 5f4943fd8c5b82c5167a7edd76b41936e295c009
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Solution {
public int GarbageCollection(string[] garbage, int[] travel) {
int len = garbage.Length;
int res = 0;
HashSet<char> s = new HashSet<char>();
for (int i = len - 1; i >= 0; i--) {
foreach (char ch in garbage[i].ToCharArray()) {
if (!s.Contains(ch))
s.Add(ch);
}
res += garbage[i].Length;
res += i > 0 ? s.Count * travel[i - 1] : 0;
}
return res;
}
}