class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param requirements string字符串
     * @param allocations string字符串
     * @return string字符串
     */
    string can_construct(string requirements, string allocations) {
        // write code here
        vector<int>ve(26);
        int n = allocations.size();
        for (int i = 0; i < n; ++i)ve[allocations[i] - 'A']++;
        int m = requirements.size();
        for (int i = 0; i < m; ++i)ve[requirements[i] - 'A']--;
        int k = ve.size();
        for (int i = 0; i < k; ++i)
            if (ve[i] < 0)return "NO";
        return "YES";
    }
};

一、题目考察的知识点

模拟

二、题目解答方法的文字分析

先记录allocations中每个字符出现的次数然后减去requirements中出现的字符的次数,如果字符数小于0那么就不行,否则就可以

三、本题解析所用的编程语言

c++