forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1200.cpp
More file actions
27 lines (19 loc) · 674 Bytes
/
1200.cpp
File metadata and controls
27 lines (19 loc) · 674 Bytes
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
class Solution {
public:
vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
sort(arr.begin(), arr.end());
int minVal = INT_MAX;
vector<vector<int>> result;
for(int i = 0; i < arr.size() - 1; i++){
int temp = abs(arr[i] - arr[i + 1]);
if(temp == minVal)
result.push_back({arr[i], arr[i + 1]});
else if(temp < minVal){
minVal = temp;
result.clear();
result.push_back({arr[i], arr[i + 1]});
}
}
return result;
}
};