⭐️ 题目描述

🌟 leetcode链接:判定是否互为字符重排
思路: 两个字符串的每个字母和数量都相等。那么 s2 一定可以排成 s1 字符串。
代码:
bool CheckPermutation(char* s1, char* s2){
    char hash1[26] = {0};
    char hash2[26] = {0};
    int i = 0;
    while (s1[i]) {
        hash1[s1[i] - 97]++;
        i++;
    }
    i = 0;
    while (s2[i]) {
        hash2[s2[i] - 97]++;
        i++;
    }
    for (i = 0; i < 26; i++) {
        if (hash1[i] != hash2[i])
            return false;
    }
    return true;
}



















