mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0300.最长上升子序列.md
Fix 300. 最长递增子序列 Java版本添加参数数组长度判断,现在可以AC
This commit is contained in:
@ -129,6 +129,7 @@ public:
|
|||||||
```Java
|
```Java
|
||||||
class Solution {
|
class Solution {
|
||||||
public int lengthOfLIS(int[] nums) {
|
public int lengthOfLIS(int[] nums) {
|
||||||
|
if (nums.length <= 1) return nums.length;
|
||||||
int[] dp = new int[nums.length];
|
int[] dp = new int[nums.length];
|
||||||
int res = 1;
|
int res = 1;
|
||||||
Arrays.fill(dp, 1);
|
Arrays.fill(dp, 1);
|
||||||
@ -137,8 +138,8 @@ class Solution {
|
|||||||
if (nums[i] > nums[j]) {
|
if (nums[i] > nums[j]) {
|
||||||
dp[i] = Math.max(dp[i], dp[j] + 1);
|
dp[i] = Math.max(dp[i], dp[j] + 1);
|
||||||
}
|
}
|
||||||
res = Math.max(res, dp[i]);
|
|
||||||
}
|
}
|
||||||
|
res = Math.max(res, dp[i]);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user