Created
February 24, 2017 03:07
-
-
Save hikilaka/b7514a7f57e6a640f803289e0e33517e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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