简单hash

超半的数

https://ac.nowcoder.com/acm/problem/22222

#include<bits/stdc++.h>
using namespace std;
int n;
int ans(int u)
{
    unordered_map<int,int>hash;
    while(u--)
    {
        int x;
        cin>>x;
        hash[x]++;
        if(hash[x]>n/2) return x;
    }
    return -1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n;
    cout<<ans(n);
    return 0;
}
全部评论

相关推荐

头像
09-05 10:14
已编辑
门头沟学院 Java
赫一鸣:我昨天投的,今天就oc了,也没和我说要面试笔试啊?不说了这单要超时了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务