思路:

先找到set的交集,然后分别计算交集中的每个元素在两个原始数组中出现的最小次数。

class Solution(object):
def intersect(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
# intersect=[]
# for i in nums1:
# while i in nums2:
# intersect.append(i)
# return intersect #注释方法超出时间 temp=list(set(nums1)&set(nums2))
intersect=[]
for i in temp:
intersect+=[i]*min(nums1.count(i),nums2.count(i)) #list除了append,可以直接+ ;注意元素加[]
return intersect

但是这种方法还是属于调用函数,和要求的哈希表等基本无关。

最新文章

  1. [转]socket 通俗解释
  2. Spring-配置bean的方法(工厂方法和Factorybean)【转】
  3. ant打包webservice jar
  4. Majority Element II
  5. 使用 Google Analytics 跟踪 JavaScript 错误
  6. 修改weblogic部署的应用名称
  7. 【LeetCode 235】Lowest Common Ancestor of a Binary Search Tree
  8. 杭电ACM2091--空心三角形
  9. stick footer布局
  10. mysql数据库开启日志
  11. 关于IDE与环境变量的一点说明
  12. netty源码学习
  13. vue 相关
  14. datatable中的copy和clone的用法区分
  15. 请问浏览器访问www.baidu.com经历了怎样的过程?
  16. Scala语言笔记 - 第一篇
  17. 将Maven项目打包成可执行jar文件(引用第三方jar)
  18. MySQL技术内幕读书笔记(八)——事务
  19. Android的TextView设置padding无效
  20. Poj3176 Cow Bowling (动态规划 数字三角形)

热门文章

  1. 谷歌翻译使用php curl请求接口文档
  2. python对大文件的处理
  3. Elasticsearch 7.0 发布都有哪些新特性
  4. H3C防火墙——回环流量问题(内网终端通过外网IP访问内部服务器)
  5. 逆向学习XXclient怎样仅仅执行一个实例
  6. 我的php站点系统分析工具01
  7. 使用Swift和SpriteKit写一个忍者游戏
  8. Jmeter简单应用
  9. js保留两位小数的解决的方法
  10. 0x28 IDA*