leetcode 给定一个大小为 n 的数组,找到其中的众数(python)
小白探索之路,记录自己的代码,并希望对你有所帮助
语言:python
class Solution:
def majorityElement(self, nums: List[int]) -> int:
se=set(nums)
a=0
c=0
for i in se:
b=nums.count(i)
if a<b:
a=b
c=i
return c
leetcode 给定一个大小为 n 的数组,找到其中的众数(python)
小白探索之路,记录自己的代码,并希望对你有所帮助
语言:python
class Solution:
def majorityElement(self, nums: List[int]) -> int:
se=set(nums)
a=0
c=0
for i in se:
b=nums.count(i)
if a<b:
a=b
c=i
return c