Simply python solution


  • 0
    L
    class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        length = len(nums)
        sorted_nums = sorted(set(nums))
        for i in sorted_nums:
            if nums.count(i) >= length/2 + 1:
                return i

  • 0
    C

    What's the runtime for this? sorting will be O(nlogn)


Log in to reply
 

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