From dd235eacd3e771464c231c9b381ae960297a7416 Mon Sep 17 00:00:00 2001 From: Alex Prudhomme Date: Sun, 15 Jan 2023 20:37:51 -0500 Subject: [PATCH] Create: 1189-maximum-number-of-balloons.cs --- csharp/1189-maximum-number-of-balloons.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 csharp/1189-maximum-number-of-balloons.cs diff --git a/csharp/1189-maximum-number-of-balloons.cs b/csharp/1189-maximum-number-of-balloons.cs new file mode 100644 index 000000000..41fbba7e4 --- /dev/null +++ b/csharp/1189-maximum-number-of-balloons.cs @@ -0,0 +1,19 @@ +public class Solution { + public int MaxNumberOfBalloons(string text) { + var charCounts = text.GroupBy(c => c) + .ToDictionary(g => g.Key, g => g.Count()); + var balloonCounts = "balloon".GroupBy(c => c) + .ToDictionary(g => g.Key, g => g.Count()); + + int result = text.Length; + foreach (var balloonCount in balloonCounts) { + if (charCounts.ContainsKey(balloonCount.Key)) { + result = Math.Min(result, charCounts[balloonCount.Key] / balloonCount.Value); + } else { + result = 0; + break; + } + } + return result; + } +} \ No newline at end of file