1 条题解

  • 0
    @ 2026-7-24 12:18:29
    # 解题思路
    
    使用计数数组,按从小到大扫描,只在次数严格更大时更新。
    
    # 复杂度
    
    - 时间复杂度:$O(n)$(若题目只有单个整数,则可视为 $O(1)$)。
    - 空间复杂度:$O(n)$ 或 $O(1)$,取决于是否需要保存数组。
    
    # 参考程序
    
    ```cpp
    #include<bits/stdc++.h>
    

    using namespace std;

    int main(){ int n,cnt[101]={0}; cin >> n; for(int i=0,x;i<n;i++){ cin >> x; cnt[x]++; } int best=0; for(int x=1;x<=100;x++) if(cnt[x]>cnt[best]) best=x; cout << best << ' ' << cnt[best]; return 0; } ```

    • 1

    【暑假作业 Day 23】出现次数最多的数

    信息

    ID
    5056
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    3
    已通过
    2
    上传者