MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / smallestDifference

Function smallestDifference

Python/SmallestDifference.py:41–62  ·  view source on GitHub ↗
(arr1 : list, arr2 : list)

Source from the content-addressed store, hash-verified

39"""
40
41def smallestDifference(arr1 : list, arr2 : list) :
42 arr1.sort();arr2.sort()
43 i = 0;j = 0
44
45 smallest = float("inf");current=float("inf")
46 smallestPair = list()
47
48 while i < len(arr1) and j < len(arr2) :
49 fnum = arr1[i];snum = arr2[j]
50
51 if fnum < snum :
52 current = snum - fnum
53 i += 1
54 elif snum < fnum :
55 current = snum - fnum
56 j += 1
57 else :
58 return [fnum, snum]
59
60 if current < smallest :
61 smallest = current
62 smallestPair.append((fnum, snum))
63
64
65

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected