Skip to content

Instantly share code, notes, and snippets.

@MitI-7
Created May 14, 2015 01:13
Show Gist options
  • Save MitI-7/9f9689c1b9a95ad65db6 to your computer and use it in GitHub Desktop.
Save MitI-7/9f9689c1b9a95ad65db6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int longestIncreasingSubsequence(const vector<int> &v) {
vector<int> dp(v.size(), INT_MAX);
for (int n : v ) {
*lower_bound(dp.begin(), dp.end(), n) = n;
}
return lower_bound(dp.begin(), dp.end(), INT_MAX) - dp.begin();
}
int main(int argc, char *argv[]) {
vector<int> v = {5, 1, 3, 2, 4};
cout << longestIncreasingSubsequence(v) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment