【leetcode】赎金信

 

bool canConstruct(char * ransomNote, char * magazine){
    int hash[26] = {0},i;
    for (i=0; magazine[i] != '\0'; i++) {
        hash[magazine[i]-97]++;
    }
    for (i=0; ransomNote[i] != '\0'; i++){
        if (!hash[ransomNote[i]-97]--) return false;
    }
    return true;
}

 

posted @ 2020-09-10 14:10  温暖了寂寞  阅读(117)  评论(0编辑  收藏  举报