Skip to content

Instantly share code, notes, and snippets.

@trhgquan
Last active October 20, 2019 03:42
Show Gist options
  • Save trhgquan/f933757368096a986dd62ad0ab2c732f to your computer and use it in GitHub Desktop.
Save trhgquan/f933757368096a986dd62ad0ab2c732f to your computer and use it in GitHub Desktop.
For more algorithm, visit https://github.com/trhgquan/CPP
/*
* longestArrays.cpp - Dynamic Programming approach.
* Code by @trhgquan - https://github.com/trhgquan
*/
int longestArrays(vector<int> a) {
vector<int> b(a.size(), 1);
int res = 1;
for (unsigned i = 1; i < a.size(); ++i){
if (a[i] >= a[i - 1]) b[i] = b[i - 1] + 1;
res = max(b[i], res);
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment