MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Array/IntersectionOfTwoArraysII.py:48–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47"""
48class Solution(object):
49 def intersect(self, nums1, nums2):
50 """
51 :type nums1: List[int]
52 :type nums2: List[int]
53 :rtype: List[int]
54 """
55 result = []
56
57
58 nums1.sort()
59 nums2.sort()
60
61 _n1 = 0
62 _n2 = 0
63
64 _n1_length = len(nums1)
65 _n2_length = len(nums2)
66
67 while _n1 < _n1_length and _n2 < _n2_length:
68 if nums1[_n1] == nums2[_n2]:
69 result.append(nums1[_n1])
70 _n1 += 1
71 _n2 += 1
72
73 elif nums1[_n1] < nums2[_n2]:
74 _n1 += 1
75 else:
76 _n2 += 1
77
78 return result

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected