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