-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution1189.cs
31 lines (27 loc) · 991 Bytes
/
Solution1189.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution1189
{
/// <summary>
/// 1189. Maximum Number of Balloons - Easy
/// <a href="https://leetcode.com/problems/maximum-number-of-balloons">See the problem</a>
/// </summary>
public int MaxNumberOfBalloons(string text)
{
var charCount = new Dictionary<char, int>();
foreach (char c in text)
{
if (charCount.ContainsKey(c))
charCount[c]++;
else
charCount[c] = 1;
}
int b = charCount.ContainsKey('b') ? charCount['b'] : 0;
int a = charCount.ContainsKey('a') ? charCount['a'] : 0;
int l = charCount.ContainsKey('l') ? charCount['l'] / 2 : 0;
int o = charCount.ContainsKey('o') ? charCount['o'] / 2 : 0;
int n = charCount.ContainsKey('n') ? charCount['n'] : 0;
return Math.Min(Math.Min(Math.Min(b, a), Math.Min(l, o)), n);
}
}