Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created February 24, 2017 03:07
Show Gist options
  • Save hikilaka/b7514a7f57e6a640f803289e0e33517e to your computer and use it in GitHub Desktop.
Save hikilaka/b7514a7f57e6a640f803289e0e33517e to your computer and use it in GitHub Desktop.
auto consecutive_array(auto input) {
auto begin = std::begin(input);
auto end = std::end(input);
std::sort(begin, end);
begin = std::begin(input);
end = std::end(input);
decltype(*begin) required;
for (auto itr = begin; itr != end;) {
auto current = itr;
auto next = std::next(itr);
if (next == end) break;
required += *next - (*current + 1);
itr = next;
}
return required;
}
int makeArrayConsecutive2(std::vector<int> statues) {
return consecutive_array(statues);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment