【1041 20 map】 Be Unique
传送门
题意
给定 \(n\) 个数字,输出第一个唯一的数字,如果没有输出 None
数据范围
\(n\leq 10^{5}\)
题解
- 两次遍历即可
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> seq(n);
unordered_map<int, int> rec;
for (auto& it : seq) {
cin >> it;
rec[it]++;
}
for (auto& it : seq) {
if (rec[it] == 1) {
cout << it;
return 0;
}
}
cout << "None";
}

浙公网安备 33010602011771号