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

  • برمجة
  • برمجة بايثون

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

الأجوبة

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)
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...