Leetcode-5197 Minimum Absolute Difference(最小绝对差)
1 #define _for(i,a,b) for(int i = (a);i < b;i ++) 2 #define _rep(i,a,b) for(int i = (a);i > b;i --) 3 #define INF 0x3f3f3f3f 4 #define MOD 1000000007 5 #define pb push_back 6 #define maxn 10003 7 8 class Solution 9 { 10 public: 11 vector<vector<int>> minimumAbsDifference(vector<int>& arr) 12 { 13 vector<vector<int>> ans; 14 sort(arr.begin(),arr.end()); 15 int diff = INF; 16 _for(i,0,arr.size()-1) 17 diff = min(diff,arr[i+1]-arr[i]); 18 19 vector<int> tmp; 20 _for(i,0,arr.size()-1) 21 { 22 tmp.clear(); 23 if(arr[i+1]-arr[i]==diff) 24 { 25 tmp.pb(arr[i]); 26 tmp.pb(arr[i+1]); 27 ans.pb(tmp); 28 } 29 } 30 return ans; 31 } 32 };