葉林
Linked with GitHub
# LeetCode - 1200. Minimum Absolute Difference ### 題目網址:https://leetcode.com/problems/minimum-absolute-difference/ ###### tags: `LeetCode` `Easy` ```cpp= /* -LeetCode format- Problem: 1200. Minimum Absolute Difference Difficulty: Easy by Inversionpeter */ class Solution { public: vector<vector<int>> minimumAbsDifference(vector<int>& arr) { vector <vector <int>> answer; int minimum = 2147483647, difference; sort(arr.begin(), arr.end()); for (int i = 1; i != arr.size(); ++i) { difference = arr[i] - arr[i - 1]; if (difference > minimum) continue; if (difference < minimum) { minimum = difference; answer.clear(); } answer.push_back( { arr[i - 1], arr[i] } ); } return answer; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up