[LeetCode C++实现]300. Longest Increasing Subsequence
这道题有个非常巧妙的方法:
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
vector<int> res;
for(int i = 0;i < nums.size();i++)
{
auto it = lower_bound(res.begin(),res.end(),nums[i]);
if(it == res.end()){
res.push_back(nums[i]);
}
else
*it = nums[i];
}
return res.size();
}
......