Update 0300.最长上升子序列.md

Fix 300. 最长递增子序列
Java版本添加参数数组长度判断,现在可以AC
This commit is contained in:
LingFenglong
2024-03-31 21:55:19 +08:00
parent e3c4c20e5e
commit 9437047fae

View File

@ -129,6 +129,7 @@ public:
```Java
class Solution {
public int lengthOfLIS(int[] nums) {
if (nums.length <= 1) return nums.length;
int[] dp = new int[nums.length];
int res = 1;
Arrays.fill(dp, 1);
@ -137,8 +138,8 @@ class Solution {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
res = Math.max(res, dp[i]);
}
res = Math.max(res, dp[i]);
}
return res;
}