Posted on

Description

Submission

class Solution {
public:
    int maxNumberOfBalloons(string text) {
        map<char, int> cntText;
        for(auto x: text) {
            cntText[x]++;
        }
        
        map<char, int> cntBalloon;
        string balloon = "balloon";
        for(auto x: balloon) {
            cntBalloon[x]++;
        }
        
        int ret = INT_MAX;
        for(auto p: cntBalloon) {
            ret = min(cntText[p.first] / p.second, ret);
        }
        return ret;
    }
};

Submission 220213

class Solution {
public:
    int maxNumberOfBalloons(string text) {
        unordered_map<char, int> freq;

        for(char ch: text) {
            freq[ch]++;
        }

        int ret = INT_MAX;
        ret = min(ret, freq['b']);
        ret = min(ret, freq['a']);
        ret = min(ret, freq['l']/2);
        ret = min(ret, freq['o']/2);
        ret = min(ret, freq['n']);
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *