最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to solve this fav singer selection code - Stack Overflow

programmeradmin1浏览0评论
def favoriteSinger(n, songs):
    singer_counts = {}
    max_count = 0
    for singer in songs:
        singer_counts[singer] = singer_counts.get(singer, 0) + 1
        max_count = max(max_count, singer_counts[singer])

    favorite_singers = 0
    for singer, count in singer_counts.items():
        if count == max_count:
            favorite_singers += 1

    return favorite_singers

n = int(input())
songs = list(map(int, input().split()))

print(favoriteSinger(n,song))

here my code not working in idle please fix the error

发布评论

评论列表(0)

  1. 暂无评论