-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1200.minimum-absolute-difference.cpp
More file actions
54 lines (46 loc) · 1.08 KB
/
1200.minimum-absolute-difference.cpp
File metadata and controls
54 lines (46 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* @lc app=leetcode id=1200 lang=cpp
*
* [1200] Minimum Absolute Difference
*/
#include "bits/stdc++.h"
using namespace std;
#define deb(x) cout<<x<<endl;
typedef vector<int> vi;
void print(vi &out){
for(auto x: out) cout<<x<<" ";
cout<<endl;
}
// @lc code=start
class Solution {
public:
vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
vector<vector<int>> output;
vector<int> temp;
sort(arr.begin(),arr.end());
int diffmn=INT_MAX;
for(int i=1;i<arr.size();i++){
diffmn=min(diffmn,(arr[i]-arr[i-1]));
}
for(int i=1;i<arr.size();i++){
temp.clear();
if(arr[i]-arr[i-1]==diffmn){
temp.push_back(arr[i-1]);
temp.push_back(arr[i]);
output.push_back(temp);
}
}
return output;
}
};
// @lc code=end
int main(){
Solution sol;
vector<vector<int>> output;
vector<int> arr={4,2,1,3};
output=sol.minimumAbsDifference(arr);
for(auto o:output){
print(o);
}
return 0;
}