Last active
October 20, 2019 03:42
-
-
Save trhgquan/f933757368096a986dd62ad0ab2c732f to your computer and use it in GitHub Desktop.
For more algorithm, visit https://github.com/trhgquan/CPP
This file contains 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
/* | |
* 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