题目链接:https://leetcode-cn.com/problems/longest-increasing-subsequence/
这里只是dp的解法:
代码:
class Solution {
public static int lengthOfLIS(int[] nums) {
int length = nums.length;
if(length<2){
return length;
}
int[] dp = new int[length];
int max = 1;//记录最长子字符串的长度
Arrays.fill(dp, 1);
for(int i = 0; i < length; i++){
for (int j = 0; j < i; j++) {
if(nums[i]>nums[j]){
dp[i] = Math.max(dp[i], dp[j]+1);
}
if(dp[i]>max){
max = dp[i];
}
}
}
return max;
}
}