Skip to content

Instantly share code, notes, and snippets.

@codyhan94
Created January 6, 2014 05:16
Show Gist options
  • Save codyhan94/8278605 to your computer and use it in GitHub Desktop.
Save codyhan94/8278605 to your computer and use it in GitHub Desktop.
int f(const vector<int> &x)
{
int longest = 2;
int p = 0;
int q = 0;
while (q < x.size())
{
int len = q - p + 1;
if (admissible(x, p, q))
{
if (len > longest)
{
longest = len;
}
}
else
{
p = q;
}
q++;
}
}
bool admissible(const vector<int> &x, int p, int q)
{
if ((p == q) || (q == p + 1)) { return true; }
if (x[q - 2] + x[q - 1] == x[q]) { return true ;}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment