leetcode算法题--“气球” 的最大数量

原题链接:https://leetcode-cn.com/problems/maximum-number-of-balloons/

class Solution {
public:
    int maxNumberOfBalloons(string text) {
        unordered_map<char ,int> mp;
        string s = "balloon";
        for (auto x : s) mp[x] = 0;
        for (auto x : text) {
            if (mp.count(x)) mp[x]++;
        }
        int res = INT_MAX;
        for (auto x : mp) {
            int k = x.first, v = x.second;
            if (k == 'l' || k == 'o')  v /= 2;
            res = min(v, res);
        }
        return res;
    }
};

你可能感兴趣的:(Algorithm,leetcode,算法,职场和发展)