350. Intersection of Two Arrays II

来源:互联网 发布:java接口自动化测试 编辑:程序博客网 时间:2024/06/05 14:39
  • 350. Intersection of Two Arrays II

Given two arrays, write a function to compute their intersection.

Example:

Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].


 用的python:

class Solution(object):    def intersect(self, nums1,nums2):        """        :type nums1: List[int]        :type nums2: List[int]        :rtype: List[int]        """               res =[]        for item in nums1:            if item in nums2:               nums2.remove(item)               res.append(item)        return res 

感觉虽然AC了,但是自己用的方法不好。。不是人家考查的点,所以还需要用c++/java再写一下思路,诸如利用java HashMap等等

未完待续…

原创粉丝点击