Skip to content

Commit dd235ea

Browse files
committed
Create: 1189-maximum-number-of-balloons.cs
1 parent fa2d4c3 commit dd235ea

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: csharp/1189-maximum-number-of-balloons.cs

+19
Original file line numberDiff line numberDiff line change
@@ -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+
.ToDictionary(g => g.Key, g => g.Count());
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

Comments
 (0)