【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; }
标签:10,guess,游戏,int,shash,char,secret,299,leetcode 来源: https://www.cnblogs.com/ganxiang/p/14218605.html