Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions csharp/1189-maximum-number-of-balloons.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}