A very easy way to use Python counter


  • 0
    L
    class Solution:
        def majorityElement(self, nums):
            from collections import Counter
            return Counter(nums).most_common()[0][0]
    

Log in to reply
 

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