3761. 唯一最小数

摘要
Title: 3761. 唯一最小数
Tag: 哈希表
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

3761. 唯一最小数

  • 题意

    给定一个长度为 n 的整数数组 a1,a2,…,an。
    请你找到数组中只出现过一次的数当中最小的那个数。
    输出找到的数的索引编号。
    a1 的索引编号为 1,a2 的索引编号为 2,…,an 的索引编号为 n。

  • 思路

    哈希表记录即可,枚举只出现一次的数

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    '''
    Author: NEFU AB-IN
    Date: 2022-04-05 19:17:38
    FilePath: \ACM\Acwing\3761.py
    LastEditTime: 2022-04-05 19:17:45
    '''
    from collections import Counter

    INF = int(1e18)
    for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    d = Counter(a)

    mp = Counter()
    for i in range(n):
    if d[a[i]] == 1:
    mp[a[i]] = i + 1

    ans = INF
    for key in d.keys():
    if d[key] == 1:
    ans = min(ans, key)
    print(mp[ans] if ans != INF else -1)
使用搜索:谷歌必应百度