int* fuzzyNumber(int* fuzzyArray, int fuzzyArrayLen, int* returnSize ) { // write code here int counts[fuzzyArrayLen+1]; for(int i=0; i<fuzzyArrayLen+1; i++) {counts[i]=-1;} int sum=0; returnSize = (int*)malloc(2*sizeof(int)); int local=0; for(int i=0; i<fuzzyArrayLen; i++) { if(fuzzyArray[i]==-1) { local=i; sum++; } else counts[fuzzyArray[i]]=i; } if(sum>1) { returnSize[0]=-1; returnSize[1]=-1; return returnSize; } else { for(int i=1; i<fuzzyArrayLen+1; i++) { if(counts[i]==-1) { returnSize[0]=local; returnSize[1]=i; break; } } return returnSize; } }
这是我本地的测试样例
int main() { int fuzzyArray[7]={1,2,5,-1,3,4,7}; int fuzzyArrayLen=7; int* returnSize; returnSize=fuzzyNumber(fuzzyArray,fuzzyArrayLen,returnSize); cout<<returnSize[0]<<"_"<<returnSize[1]; return 0; }
这是输出
求告知
全部评论
(2) 回帖