【leetcode】299. 猜数字游戏

 

char * getHint(char * secret, char * guess){
    int shash[10]={0};
    int ghash[1000]={0};
    int i, len=strlen(secret), A=0, B=0, l=0;
    char* s=(char*)calloc(10,sizeof(char));
    for (i=0; i<len; i++)
    {
        shash[secret[i]-'0']++;
        if(secret[i]==guess[i]){
            shash[secret[i]-'0']--;
            ghash[i]++;
            A++;
        }
    }
    for (i=0; i<len; i++)
    {
        if(ghash[i])
            continue;
        if(shash[guess[i]-'0']>0){
            shash[guess[i]-'0']--;
            B++;
        }
    }
    sprintf(s,"%dA%dB",A,B);
    return s;
}

 

上一篇:攻防世界-web NewsCenter


下一篇:纵横杯2020 MISC部分WP