Python解法代码: class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: nums1.sort() nums2.sort() r = [] i = j = 0 while i < len(nums1) and j < len(nums2): if nums1[i] == nums2[j]: r.append(nums1[i]) i += 1 j += 1 elif n
题目描述: Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as many times as it shows in both arrays. The result can be in a
思路: 先找到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 num
-- 克隆 function Clone(object) local lookup_table = { } local function _copy(object) if type(object) ~= "table" then return object elseif lookup_table[object] then return lookup_table[object] end local new_table = { } lookup_table[object] = new_ta