class Solution:
def majorityElement(self, nums: List[int]) -> int:
dic={}
num_list=len(nums)
for num in nums:
if num in dic.keys():
dic[num]+=1
else:
dic[num]=1
if dic[num]>=num_list/2:
return num
169多数元素leetcode 字典法解决
最新推荐文章于 2024-08-26 16:25:39 发布