首页 > 编程语言 > 详细

leetcode169 python3 92ms 求众数

时间:2018-08-04 22:50:45      阅读:165      评论:0      收藏:0      [点我收藏+]
class Solution:
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        freq = {}
        for i in nums:
            if i not in freq.keys():
                freq[i] = 1
            else:
                freq[i] += 1
            if freq[i] > len(nums)//2:
                return i
        

leetcode169 python3 92ms 求众数

原文:https://www.cnblogs.com/theodoric008/p/9420376.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!