728x90
반응형
int minimumAbsoluteDifference(vector<int> arr) {
sort(arr.begin(),arr.end());
int diff = INT_MAX;
for(int i = 0;i<arr.size()-1;i++)
{
if(abs(arr[i]-arr[i+1])<diff)
{
diff = abs(arr[i]-arr[i+1]);
}
}
return diff;
}
728x90
반응형
'개발 > 코딩' 카테고리의 다른 글
해커랭크(HackerRank) - Almost Sorted // C++ (0) | 2021.05.19 |
---|---|
해커랭크(HackerRank) - The Grid Search // C++ (0) | 2021.05.16 |
LeetCode - Two Sum / c++ (0) | 2020.07.24 |
해커랭크(HackerRank) - Closest Numbers / C++ (0) | 2020.07.11 |
해커랭크(HackerRank) - The Full Counting Sort / C++ (0) | 2020.07.11 |
댓글