```
#include <algorithm>
#include <vector>
using namespace std;
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
int len = nums.size();
if (0 == len)return 0;
int maxLen = 1;
auto begin = nums.begin();
for (int i = 1; i < len; ++i)
{
auto ret = std::lower_bound(begin, begin + maxLen, nums[i]);
if (ret == begin + maxLen)//maxLen + 1
*(begin + maxLen++) = nums[i];
else if (nums[i] < *ret)
*ret = nums[i];
}
return maxLen;
}
};
```