-->
当前位置:首页 > 题库 > 正文内容

FILL_IN_THE_BLANK_FOR_PROGRAMMING:The Largest Missing Integer

Luz3年前 (2021-05-10)题库293
Given an array `a[]`of `n` integers, the function `MissingMax` is to find and return the maximum negative integer which is **NOT** in the array. For example, given { -3, -1, 8, 1, 0 }, -2 is the largest negative integer which is missing.
```c++
int MissingMax( int a[], int n )
{
int i, j, max, missing = -1;
for( i=0; imax = i;
for( j = i+1; j < n; j++ )
if (@@[a[j]>a[max]](3)) max = j;
if ( max != i ) swap(a[i], a[max]);
if ( a[i] == missing ) missing--;
else if ( a[i] < missing ) @@[break](3);
}
return missing;
}
```






answer:The first empty: a [J] > a [Max]
Second empty: break

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。