每日一题·暑假 week1

3761. 唯一最小数

https://www.acwing.com/problem/content/3764/

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<unordered_map>
using namespace std;
typedef long long LL;
int T;
const int N = 2e5+5;
int n;
int a[N];
unordered_map<int,int> m;
int main(){
    cin >> T;
    while(T--){
        m.clear();
        int ans = -1;
        cin >> n;
        for(int i = 1; i <= n; i++){
            scanf("%d",&a[i]);
            if(m[a[i]] != 0){
                m[a[i]] = -1;
            }
            else {
                m[a[i]] = i;
            }
        }
        sort(a+1,a+n+1);
        for(int i = 1;i <= n; i++){
            if(m[a[i]] != -1){
                ans = m[a[i]];
                break;
            }
        }
        cout<<ans<<endl;
    }
  return 0;
}
//  freopen("testdata.in", "r", stdin);

上一篇:leetcode 66 加一


下一篇:js利用递归与promise 按顺序请求数据