本题很简单,由于 ,用 map 记录每个数字出现的次数,最后遍历数组找到出现奇数次的那一个数字即可。
#include<bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int, int> mp;
int a[100005];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
}
for (int i = 1; i <= n; i++) {
if (mp[a[i]] % 2 != 0) {
cout << a[i] << endl;
return 0;
}
}
return 0;
}