首页 > 其他 > 详细

【leetcode】珠玑妙算

时间:2020-09-21 10:39:30      阅读:40      评论:0      收藏:0      [点我收藏+]

 

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;
}

 

【leetcode】珠玑妙算

原文:https://www.cnblogs.com/ganxiang/p/13703938.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!