From a3a8182d28006fbc9d6003dc5907b543c1dba647 Mon Sep 17 00:00:00 2001 From: fwqaaq Date: Tue, 18 Jul 2023 15:42:47 +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=20=E4=BC=98=E5=8C=96=20?= =?UTF-8?q?Rust=20=E5=92=8C=20Java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0300.最长上升子序列.md | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/problems/0300.最长上升子序列.md b/problems/0300.最长上升子序列.md index c58c3bf6..8287c777 100644 --- a/problems/0300.最长上升子序列.md +++ b/problems/0300.最长上升子序列.md @@ -130,18 +130,16 @@ Java: class Solution { public int lengthOfLIS(int[] nums) { int[] dp = new int[nums.length]; + int res = 0; Arrays.fill(dp, 1); - for (int i = 0; i < dp.length; i++) { + for (int i = 1; i < dp.length; i++) { for (int j = 0; j < i; j++) { if (nums[i] > nums[j]) { dp[i] = Math.max(dp[i], dp[j] + 1); } + res = Math.max(res, dp[i]); } } - int res = 0; - for (int i = 0; i < dp.length; i++) { - res = Math.max(res, dp[i]); - } return res; } } @@ -291,7 +289,7 @@ function lengthOfLIS(nums: number[]): number { Rust: ```rust pub fn length_of_lis(nums: Vec) -> i32 { - let mut dp = vec![1; nums.len() + 1]; + let mut dp = vec![1; nums.len()]; let mut result = 1; for i in 1..nums.len() { for j in 0..i { @@ -306,13 +304,6 @@ pub fn length_of_lis(nums: Vec) -> i32 { ``` - - - - - - -