题解 | #相助#
相遇
https://ac.nowcoder.com/acm/contest/83687/A
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n == 1){
cout<<-1;
return 0;
}
int num[500005];
int one = 0;
int zero = 0;
for(int i = 0; i < n; i++){
cin>>num[i];
}
if(num[0] == num[n-1]) cout<<1;
else{
int a = num[0];
int b = num[n-1];
int ai;
for(ai = 1; ai < n; ai++){
if(num[ai] == a) break;
}
int bi;
for(bi = n - 2; bi >= 0; bi--){
if(num[bi] == b) break;
}
if(ai < bi) cout<<2;
else cout<<-1;
}
return 0;
}