Super easy python solution by using dict


  • 0
    E

    '''
    class Solution(object):
    def majorityElement(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    dic={}
    i=0
    for n in nums:
    if n in dic:
    dic[n]+=1
    else:
    dic[n]=1
    for key, value in dic.items():
    if value>(len(nums)/2):
    return key

    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.