You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to git a star :) )
int minimumAbsoluteDifference(std::vector<int> _nums) { std::sort(_nums.begin(), _nums.end()); int diffMin = std::numeric_limits<int>::max(); int tempMin = std::numeric_limits<int>::max(); for(auto it1 = _nums.cbegin(), it2 = it1 + 1; it2 != _nums.cend(); ++it1, ++it2 ){ tempMin = std::abs(*it1 - *it2); if(tempMin == 0){ return 0; } if(tempMin < diffMin){ diffMin = tempMin; } } return diffMin; }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Absolute Difference in an Array
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to git a star :) )