给定两个字符串newspaper和message,判定message是否能用newspaper中的字符组成

给定两个字符串newspaper和message,判定message是否能用newspaper中的字符组成。

分析:message中用到的字符必须出现在newspaper中。其次,message中任意字符出现的次数一定少于其在newspaper中出现的次数。统计一个元素集中元素出现的次数,我们就应该想到hash table。

bool canCompose(string newspaper,string message)
{
    unordered_map hashMap;
    int i=0;
    if(newspaper.length() < message.length())
    {
        return false;
    }

    for(i=0;i

 

你可能感兴趣的:(算法)