题解 | #频繁元素#90%通过率看过来

频繁元素

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

n = int(input())
lst = list(map(int, input().split()))
s = set(lst)
dic = {}
for i in s:
    dic[i] = lst.count(i)
count_max = 0
for key in dic:  # 现在的字典会的key会自动以字典序升序排序,这里就会导致先遍历到的不是列表中最先出现的数据
    count = dic.get(key)
    if count > count_max:
        count_max = count
for i in lst:
    if lst.count(i) == count_max:
        print(i)
        break

全部评论

相关推荐

10-17 17:54
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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