当前位置:网站首页>1041 be unique (20 points (s)) (hash: find the first number that occurs once)
1041 be unique (20 points (s)) (hash: find the first number that occurs once)
2022-07-06 12:33:00 【Vigorous waist Nuo dance】
title
Ideas
Two things are needed : One is a table that records the sequence , One is a table that records the number of times
Code
#include <iostream>
using namespace std;
int hashtable[100100], num[100100];
#define rep(i,j,k) for(int i=j;i<k;i++)
int main() {
int n;
cin >> n;
rep(i, 0, n) {
cin >> num[i];
hashtable[num[i]]++;
}
rep(i, 0, n)
if (hashtable[num[i]] == 1) {
cout << num[i];
return 0;
}
cout << "None";
}
doubt
I don't know why I'm wrong ╮(╯_╰)╭
using namespace std;
#include <unordered_map>
#define rep(i,j,k) for(int i=j;i<k;i++)
#include <iostream>
int main() {
unordered_map<int, int>bets;
int n, temp;
cin >> n;
rep(i, 0, n) {
cin >> temp;
bets[temp]++;
}
for (auto i : bets) {
//cout << i.second << endl;
if (i.second == 1) {
cout << i.first;
return 0;
}
}
cout << "None";
return 0;
}
边栏推荐
猜你喜欢

Conditional probability

level16

(1) Introduction Guide to R language - the first step of data analysis

Common properties of location

Derivation of logistic regression theory
![[Nodejs] 20. Koa2 onion ring model ----- code demonstration](/img/a8/a4390238685903b63bb036206f8dcb.jpg)
[Nodejs] 20. Koa2 onion ring model ----- code demonstration

Whistle+switchyomega configure web proxy

Understanding of AMBA, AHB, APB and Axi

Walk into WPF's drawing Bing Dwen Dwen

基于Redis的分布式锁 以及 超详细的改进思路
随机推荐
Naive Bayesian theory derivation
@Autowired 和 @Resource 的区别
Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
Page performance optimization of video scene
Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
[Red Treasure Book Notes simplified version] Chapter 12 BOM
Basic operations of databases and tables ----- view data tables
Unity场景跳转及退出
ES6语法总结--下篇(进阶篇 ES6~ES11)
Database course design: college educational administration management system (including code)
Mysqldump error1066 error solution
Walk into WPF's drawing Bing Dwen Dwen
[Offer29] 排序的循环链表
Common properties of location
[899] ordered queue
CUDA C programming authoritative guide Grossman Chapter 4 global memory
ORA-02030: can only select from fixed tables/views
ESP learning problem record
Kconfig Kbuild
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique