Write a Python program to find the majority element from a given array of size n using Collections module
- برمجة
- برمجة بايثون
- 2021-04-16
- salsabeelalhams99111801528
الأجوبة
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)أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال