Maintaining the DP [] array, by a state transition equation: dp [i] = Math.max (dp [i], dp [j] +1); When implemented when the state transition equation num [j] nums [i]> when the condition is not satisfied, skip this time j, does not operate. cycle interval is j for (0, i);
//经典的动态规划问题:DP解决。
public int lengthOfLIS1(int[] nums) {
if (nums.length == 0){
return 0;
}
int[] dp = new int[nums.length];
Arrays.fill(dp,1);
int res = 0;
for (int i = 0; i < nums.length; i++) {
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i]){
dp[i] = Math.max(dp[i],dp[j] + 1);
}
}
res = Math.max(res,dp[i]);
}
return res;
}