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 };
原文地址:https://www.cnblogs.com/Asurudo/p/11566936.html
时间: 2024-11-03 16:37:57