\
int hash(char c){
return c-'a';
}
bool canConstruct(char* ransomNote, char* magazine) {
if(!ransomNote) return true;
if(!magazine) return false;
int a[26]={0};
int b[26]={0};
int i=0,j=0;
while(ransomNote[i]!=0){
a[hash(ransomNote[i++])]++;
}
while(magazine[j]!=0){
b[hash(magazine[j++])]++;
}
if(i>j) return false;
for(int x=0;x<26;x++){
if(a[x]>b[x]) return false;
}
return true;
}
结果:
标签:ransomNote,return,int,++,magazine,383,赎金,hash From: https://www.cnblogs.com/llllmz/p/18041651