题目描述链接:https://leetcode-cn.com/problems/smallest-difference-lcci/
解题思路:排序+双指针
LeetCode C++求解参考代码:
class Solution { public: int smallestDifference(vector<int>& a, vector<int>& b) { sort(a.begin(),a.end()); sort(b.begin(),b.end()); long res=INT_MAX; for(int i=0,j=0;i<a.size()&&j<b.size();){ res=min(abs(long(a[i])-long(b[j])),res); if(a[i]<b[j]){ i++; } else{ j++; } } return res; } };