1. 问题描述
在给定的数组中,找到出现次数最多的数字。
出现次数相同时,返回数值最小的数字。
2. 样例
样例 1:
输入:
[1,1,2,3,3,3,4,5]
输出:
3
样例 2:
输入:
[1]
输出:
1
3. 代码
class Solution:
"""
@param array: An array.
@return: An integer.
"""
def findNumber(self, array):
# Write your code here.
count = {}
for item in sorted(array):
if item not in count.keys():
count[item] = 1
else:
count[item] += 1
return sorted(count.items(), key=lambda x: x[1], reverse=True)[0][0]