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
        
posted @ 2018-08-04 22:13  一条图图犬  阅读(331)  评论(0编辑  收藏  举报