350. Intersection of Two Arrays II - LeetCode

xiaoxiao2021-02-28  80

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等等

未完待续…

转载请注明原文地址: https://www.6miu.com/read-36590.html

最新回复(0)