Given a non-empty array of N integers A, please find the smallest integer P such that all the numbers in A are in the subarray A[0…P].
Input Format:
A positive number N, followed by a list of N non-negative integers less than 1000000. N is no larger than 1000000.
Output Format:
The smallest integer P.
Sample Input:
5
2 2 1 0 1
Sample Output:
3
我的代码:
/**帽***/
#include <stdio.h>
int main(){
int a[1000000]={0},i,n,k;
scanf("%d",&n);
int index=0;
for(i=0;i<n;i++){
scanf("%d",&k);
if(a[k]==0){
a[k]=1;
index=i;
}
}
printf("%d",index);
return 0;
}
我知道很简单,但我花了好多时间才读懂题,岂可修!!!
顺便这是我自己用来测试的一个例子:
10 5 2 0 3 5 4 7 8 9 6