题解 | 小红的数组清空

小红的数组清空

https://www.nowcoder.com/practice/c0784de498ca4779b3dc2a75fddcf12b

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    map<int,int>m;
    for(int i=0;i<n;i++){
        int v;
        cin>>v;
        m[v]++;
    }
    int ans=0;
    for(auto [x,y]:m){
        int now=m[x],la=m[x-1];
        ans+=max(now-la,0);
    }
    cout<<ans<<endl;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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