/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* masterMind(char* solution, char* guess, int* returnSize){
int* ans=(int*)calloc(2,sizeof(int));
*returnSize=2;
ans[0]=0;
ans[1]=0;
int flag[4]={0};
int flag1[4]={0};
for(int a=0;a<4;a++){
if(solution[a]==guess[a]){
ans[0]++;
flag[a]=1;
flag1[a]=1;
}
}
for(int a=0;a<4;a++){
for(int b=0;b<4;b++){
if(guess[b]==solution[a]&&flag[a]==0&&flag1[b]==0){
ans[1]++;
flag[a]=1;
flag1[b]=1;
}
}
}
return ans;
}
力扣------ 珠玑妙算
最新推荐文章于 2024-09-03 18:29:17 发布