class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int l=ransomNote.size();
int l1=magazine.size();
if(l>l1)
return false;
vector<bool>pp(l1,false);
for(int i=0;i<l;i++)
{
bool flag=true;
for(int j=0;j<l1;j++)
{
if(pp[j]==false&&ransomNote[i]==magazine[j])
{
pp[j]=true;
flag=false;
break;
}
}
if(flag)
return false;
}
return true;
}
};
暴力,两层循环
但是,也可以统计26个字母出现次数,仅需遍历一次