题解 | #小欧的数组修改#

小欧的数组修改

https://www.nowcoder.com/practice/9d57195bcec9415e9d12db846545ee0f

#include <bits/stdc++.h>
using namespace std;
map<int, int>times;
int main() {
    int n, maxx = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int temp;
        cin >> temp;
        times[temp]++;
        maxx = max(maxx, times[temp]);
    }
    cout << min(maxx + 1, n);
}
// 64 位输出请用 printf("%lld")

直接读入, 利用map来储存每个字母出现的次数(比数组好使), 输出的句子是为了避免所有的数字都是同一数字, 没法修改的情况, 其余情况都是最大值+1就好。

#悬赏#
全部评论

相关推荐

12-15 14:16
门头沟学院 Java
回家当保安:发offer的时候会背调学信网,最好不要这样。 “27届 ”和“28届以下 ”公司招聘的预期是不一样的。
实习简历求拷打
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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