【LeetCode】C++ :簡單題 - 雜湊表 1189. “氣球” 的最大數量
阿新 • • 發佈:2021-01-25
難度簡單47
給你一個字串
text
,你需要使用text
中的字母來拼湊儘可能多的單詞"balloon"(氣球)。字串
text
中的每個字母最多隻能被使用一次。請你返回最多可以拼湊出多少個單詞"balloon"。示例 1:
輸入:text = "nlaebolko" 輸出:1示例 2:
輸入:text = "loonbalxballpoon" 輸出:2示例 3:
輸入:text = "leetcode" 輸出:0提示:
1 <= text.length <= 10^4
text
全部由小寫英文字母組成
這就是人與人之間的差距嗎。。。嗚嗚嗚┭┮﹏┭┮
class Solution { public: int maxNumberOfBalloons(string text) { unordered_map<char, int> ump; for(auto ch: text){ ump[ch]++; } return min({ump['b'], ump['a'], ump['l']/2, ump['o']/2, ump['n']}); } };