题解 | #频繁元素#

频繁元素

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

这个思路值得学习

using namespace std;
#define int long long
#define endl '\n'
signed main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;cin>>n;int a[21]={0};
    int max=0,p;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        a[m]++;
        if(a[m]>max)
        {
            max=a[m];
            p=m;
        }
    }
    cout<<p<<endl;
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务