classSolution { private: int dp[2505]; public: intbs(int s, int e, int key){ while (s <= e) { if (s == e) return s; int mid = (s + e) >> 1; if (dp[mid] < key) s = mid + 1; else e = mid; } return0; }
intlengthOfLIS(vector<int> &nums){ dp[0] = -1e9; int top = 0; for (int i = 0; i < nums.size(); i++) { if (nums[i] > dp[top]) dp[++top] = nums[i]; else { int k = bs(1, top, nums[i]); dp[k] = nums[i]; } } return top; } };