题目
更好的方法是耐心排序,参见《算法小抄》的内容!!!
基础解法必须掌握!!!
class Solution {
public int lengthOfLIS(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int maxLen = 1, n = nums.length;
int[] dp = new int[n]; // 以i结尾的LIS
Arrays.fill(dp, 1);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (nums[i] > nums[j] && (dp[j] + 1 > dp[i])) {
dp[i] = dp[j] + 1;
maxLen = Math.max(maxLen, dp[i]);
}
}
}
return maxLen;
}
}