class Solution():
#求最多的数
def find_max(self,list):
num = 0
for i in list:
print(i)
if list.count(i) > num:
num = list.count(i)
value = i
return value #求最多且最大的数
def find_most_num(self,list):
num = 0
most = 0
for i in list:
print(i)
if list.count(i) >= num:
if i > most:
most = i
num = list.count(i)
return most
#另一种算法
def find_most_dict(self,list):
dict = {}
for i in list:
if i in dict.keys():
dict[i] += 1
else:
dict[i] = 1
print(dict)
max = 0
for k,v in dict.items():
if v >= max:
value = k
max = v
if k > value:
value = k
return value if __name__ =='__main__':
list = [1,2,8,13,3,4,8,8,2,5,3,1,2,4,5,5,2,8,19,8,2]
solution = Solution()
# result = solution.find_max(list)
# print('==============')
# print(result)
print('=====================================')
#result2 = solution.find_most_num(list)
print('==============')
#print(result2)
result3 = solution.find_most_dict(list)
print('==============')
print(result3)

最新文章

  1. Socket聊天程序——客户端
  2. EasyUI刚加载时候Window窗体自动弹出的解决办法
  3. 深入instanceof
  4. CocoaPods安装及使用详情
  5. js高级群的一些整理6月
  6. python窗体——pyqt初体验
  7. ie8中支持 password 的 placeholder
  8. JsRender系列demo(9)自定义函数
  9. what is WLAN ? when and why we need use it ?
  10. NFC(9)NDEF文本格式规范及读写示例(解析与封装ndef 文本)
  11. 使用 testng.xml 参数化
  12. 《Effective C++》Item2:尽量以const,enum,inline替换#define
  13. 【Lucene】近实时搜索
  14. Chapter 1 First Sight——9
  15. 【Javascript语言精粹】笔记摘要
  16. 菜鸟级Git GitHub创建仓库
  17. BZOJ1412[ZJOI2009]狼和羊的故事——最小割
  18. P1036 选数 题解
  19. 如何将web项目部署到Ubuntu服务器上
  20. mysql分享二-防止sql注入

热门文章

  1. 基于 BDD 理论的 Nebula 集成测试框架重构(上篇)
  2. week-02
  3. GO学习-(16) Go语言基础之文件操作
  4. Scrapy爬虫返回302重定向问题解决方法
  5. uwsgi启动Django应用
  6. Docker学习(14) Docker容器的数据管理
  7. CUDA Pro:通过向量化内存访问提高性能
  8. 孟老板 BaseAdapter封装 (一) 简单封装
  9. fail2ban防护ssh免于暴力破解
  10. 网页站点下载器teleport ultra