Find the Distance Value Between Two Arrays LeetCode solution in Python
1class Solution:2def findTheDistanceValue(self, array1: List[int], array2: List[int], d: int) -> int:34result = 056array2 = sorted(array2)78for num in array1:910flag = True1112low = 013high = len(array2) - 11415while low <= high:1617mid = (low + high) // 21819if abs(array2[mid] - num) <= d:20flag = False21break2223elif array2[mid] > num:24high = mid - 12526else:27low = mid + 12829if flag == True:3031result = result + 13233return result