python 2 lines using Counter


  • 0
    D
    def majorityElement(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            
            from collections import Counter
            return Counter(nums).most_common(1)[0][0]
    

Log in to reply
 

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