class Solution(object): def intersection(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ nums1=set(nums1) nums2=set(nums2) return list(nums1&nums2)
make it 1 :)
def intersection(self, nums1, nums2): return list(set(nums1) & set(nums2))
def intersection(self, nums1, nums2):
i =  for k in nums1: if k in nums2 and k not in i: i.append(k) return i
@cheffyu because this answer just used the python implementation of intersection, it is same as
If you do this during interview, it would definitely not impress the interviewer.
I think the reason is that this is not an algorithm solution. The "intersection" operation of two arrays ("lists" here in Python) should be IMPLEMENTED, rather then USED. The problems here we are working on are under the topic of "Algorithm", and this solution just uses the built-in (it's good, but it's not the wanted one). If Python can use all its built-in and libraries, many hard problems here is not a real problem.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.