L387 The Smallest Difference
Given two array of integers(the first array is arrayA
, the second array is arrayB
), now we are going to find a element in array A which is A[i], and another element in array B which is B[j], so that the difference between A[i] and B[j] (|A[i] - B[j]|) is as small as possible, return their smallest difference.
Example
For example, given array A =[3,6,7,4]
, B =[2,8,9,3]
, return0
O(n_log_n) time
先排序,然后再两个指针来扫两个数组,边扫边找。
Last updated