1200. Minimum Absolute Difference 發表於 2023-02-13 | 分類於 leetcode problemsolution12345678910111213class Solution {public: vector<vector<int>> minimumAbsDifference(vector<int>& arr) { vector<vector<int>> ret; sort(arr.begin(),arr.end()); int mn_abs = arr[1] - arr[0], n = arr.size(); for(int i=1;i<n ; ++i) mn_abs = min(mn_abs, arr[i] - arr[i-1]); for(int i=1;i<n;++i){ if(arr[i] - arr[i-1] == mn_abs) ret.push_back({arr[i-1], arr[i]}); } return ret; }}; analysis time complexity O(nlogn) space complexity O(1)