Q:

Write a Python program to find the majority element from a given array of size n using Collections module

0

Write a Python program to find the majority element from a given array of size n using Collections module

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import collections
class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :return type: int
        """
        count_ele=collections.Counter(nums)
        return count_ele.most_common()[0][0]

result = Solution().majorityElement([10,10,20,30,40,10,20,10])
print(result)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now