当前位置:网站首页>Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding

Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding

2022-07-07 05:31:00 HERODING23

 Insert picture description here
Their thinking :
Count the number of all letters , And then according to balloon The number of five letters in a word , Count the maximum number of words that can be formed ( Take the minimum value that each letter can form the most words ), The code is as follows :

class Solution {
    
public:
    int maxNumberOfBalloons(string text) {
    
        vector<int> count(26, 0);
        for(auto c : text) {
    
            count[c - 'a'] ++;
        }
        int ans = min(count[1], min(count[0], min(count['l' - 'a'] / 2, min(count['o' - 'a'] / 2, count['n' - 'a']))));
        return ans;
    }
};
原网站

版权声明
本文为[HERODING23]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130734575791.html