【leetcode】珠玑妙算

 

int* masterMind(char* solution, char* guess, int* returnSize){
    int* arr = (int*)calloc(2,sizeof(int));
    int s_hash[26] = {0};
    int g_hash[26] = {0};
    int i;
    for (i=0; i<4; i++)
    {
        if (solution[i] != guess[i])
        {
            s_hash[solution[i]-'A']++;
            g_hash[guess[i]-'A']++;
        }
        else
            arr[0]++;
    }
    for (i=0; i<26; i++)
    {
        if (s_hash[i] && g_hash[i]) arr[1] += (s_hash[i] < g_hash[i])? s_hash[i]: g_hash[i];
    }
    *returnSize=2;
    return arr;
}

 

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