llllmz

导航

242. 有效的字母异位词 C

int hash(char c){
    return c-'a';
}

bool isAnagram(char* s, char* t) {
    int a[26]={0};
    int b[26]={0};
    int i=0;
    while(s[i]!=0){
        a[hash(s[i++])]++;
    }
    i=0;
    while(t[i]!=0){
        b[hash(t[i++])]++;
    }
    for(i=0;i<26;i++){
        if(a[i]!=b[i]) return false;
    }
    return true;
}

结果:

posted on 2024-02-28 17:54  神奇的萝卜丝  阅读(8)  评论(0)    收藏  举报