From 9437047fae6056b05e731f16eb3d7625b9c5bed5 Mon Sep 17 00:00:00 2001 From: LingFenglong <2808021998@qq.com> Date: Sun, 31 Mar 2024 21:55:19 +0800 Subject: [PATCH] =?UTF-8?q?Update=200300.=E6=9C=80=E9=95=BF=E4=B8=8A?= =?UTF-8?q?=E5=8D=87=E5=AD=90=E5=BA=8F=E5=88=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix 300. 最长递增子序列 Java版本添加参数数组长度判断,现在可以AC --- problems/0300.最长上升子序列.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/problems/0300.最长上升子序列.md b/problems/0300.最长上升子序列.md index 6d82eae1..199ae59e 100644 --- a/problems/0300.最长上升子序列.md +++ b/problems/0300.最长上升子序列.md @@ -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; }