We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fa2d4c3 commit dd235eaCopy full SHA for dd235ea
csharp/1189-maximum-number-of-balloons.cs
@@ -0,0 +1,19 @@
1
+public class Solution {
2
+ public int MaxNumberOfBalloons(string text) {
3
+ var charCounts = text.GroupBy(c => c)
4
+ .ToDictionary(g => g.Key, g => g.Count());
5
+ var balloonCounts = "balloon".GroupBy(c => c)
6
7
+
8
+ int result = text.Length;
9
+ foreach (var balloonCount in balloonCounts) {
10
+ if (charCounts.ContainsKey(balloonCount.Key)) {
11
+ result = Math.Min(result, charCounts[balloonCount.Key] / balloonCount.Value);
12
+ } else {
13
+ result = 0;
14
+ break;
15
+ }
16
17
+ return result;
18
19
+}
0 commit comments