From 5f4943fd8c5b82c5167a7edd76b41936e295c009 Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Mon, 20 Nov 2023 22:50:33 +0530 Subject: [PATCH 1/3] feat: add cs solution to lc problem: No.2391 --- .../Solution.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/Solution.cs diff --git a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/Solution.cs b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/Solution.cs new file mode 100644 index 0000000000000..d6f56689f606f --- /dev/null +++ b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/Solution.cs @@ -0,0 +1,16 @@ +public class Solution { + public int GarbageCollection(string[] garbage, int[] travel) { + int len = garbage.Length; + int res = 0; + HashSet s = new HashSet(); + 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; + } +} From 805000bd7c0bebf8b0da1e5bf8ae6c39e2a3052d Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Mon, 20 Nov 2023 22:52:27 +0530 Subject: [PATCH 2/3] Update README_EN.md to lc problem: No.2391 --- .../README_EN.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md index d9a3dc8f2d49d..b631efb851fb2 100644 --- a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md +++ b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README_EN.md @@ -346,6 +346,27 @@ impl Solution { } ``` +### **C#** + +```cs +public class Solution { + public int GarbageCollection(string[] garbage, int[] travel) { + int len = garbage.Length; + int res = 0; + HashSet s = new HashSet(); + 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; + } +} +``` + ### **...** ``` From 4919f1f2e71f090f6facea75edd90be2c119f6ce Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Mon, 20 Nov 2023 22:53:05 +0530 Subject: [PATCH 3/3] Update README.md to lc problem: No.2391 --- .../README.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md index 817f8fbc6cb69..797701b8ac2a0 100644 --- a/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md +++ b/solution/2300-2399/2391.Minimum Amount of Time to Collect Garbage/README.md @@ -365,6 +365,27 @@ impl Solution { } ``` +### **C#** + +```cs +public class Solution { + public int GarbageCollection(string[] garbage, int[] travel) { + int len = garbage.Length; + int res = 0; + HashSet s = new HashSet(); + 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; + } +} +``` + ### **...** ```