leetcode169 python3 92ms 求众数

Posted 一条图图犬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode169 python3 92ms 求众数相关的知识,希望对你有一定的参考价值。

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 求众数的主要内容,如果未能解决你的问题,请参考以下文章