给定一个长度为 的整数数组
。
请你找到数组中只出现过一次的数当中最小的那个数。
输出找到的数的索引编号。
的索引编号为
,
的索引编号为
,…,
的索引编号为
。
输入格式
第一行包含整数 ,表示共有
每组数据第一行包含整数 。
第二行包含 个整数
。
输出格式
每组数据输出一行结果,即满足条件的数的索引编号,如果不存在满足条件的数,则输出 −1
。
数据范围
同一测试点内的所有 的和不超过
。
输入样例:
6
2
1 1
3
2 1 3
4
2 2 2 3
1
1
5
2 3 2 4 2
6
1 1 5 5 4 4
输出样例:
-1
2
4
1
2
-1
#include<iostream>
#include<unordered_map>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 200010;
int pos[N];
int main(){
int t;
scanf("%d", &t);
int n;
while(t--){
unordered_map<int, int> cnt;
scanf("%d", &n);
int x;
for(int i = 1; i <= n; i++){
scanf("%d", &x);
pos[x] = i;
cnt[x]++;
}
int res = -1;
for(auto &p: cnt)
if(p.y == 1 && (res == -1 || p.x < res))
res = p.x;
if(res == -1) puts("-1");
else printf("%d\n", pos[res]);
}
return 0;
}