// O(nlogn) class Solution { public: int lengthOfLIS(vector<int>& nums) { int n = nums.size(); if (n < 1) return 0; vector<int> dp; dp.push_back(nums[0]); for (int i = 1; i < n; i++) { auto p = lower_bound(dp.begin(), dp.end(), nums[i]); if (p == dp.end()) dp.push_back(nums[i]); else *p = nums[i]; } return dp.size(); } }; /* // O(n*n) class Solution { public: int lengthOfLIS(vector<int>& nums) { int n = nums.size(); if (n < 1) return 0; vector<int> dp(n, 1); int res = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) if (nums[i] > nums[j]) dp[i] = max(dp[i], dp[j] + 1); res = max(res, dp[i]); } return res; } }; */