Skip to content

Instantly share code, notes, and snippets.

@junioramilson
Created July 22, 2018 23:08
Show Gist options
  • Select an option

  • Save junioramilson/1753eb160f74fc1c58edbaca4a8ab3ee to your computer and use it in GitHub Desktop.

Select an option

Save junioramilson/1753eb160f74fc1c58edbaca4a8ab3ee to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
int main()
{
std::vector<int> sequence = { 0, 2, 4, 5};
int near = 2;
for (int i = 0; i < sequence.size(); i++)
{
int curr_v = sequence[i];
if (curr_v > 1)
{
if (curr_v == near)
near++;
else if (curr_v > near)
near = ((near - 1) > (curr_v - 1)) ? curr_v++ : near++;
}
}
std::cout << near << '\n';
system("pause");
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment