必须掌握,O(N^2) + O(N)
class Solution {
public int lengthOfLIS(int[] nums) {
int[] dp = new int[nums.length];
Arrays.fill(dp, 1);
int res = 1;
for (int i = 1; i < nums.length; ++i) {
for (int j = 0; j < i; ++j) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
res = res > dp[i] ? res : dp[i];
}
return res;
}
}
O(NlgN) + O(N)
patience sorting(耐心排序),参考《算法小抄》p100,介绍详细!