From b42feba6057eab0cbb5f25709b3d5d77b3a073c3 Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年7月18日 17:25:21 +0800 Subject: [PATCH] =?UTF-8?q?Update=200718.=E6=9C=80=E9=95=BF=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=AD=90=E6=95=B0=E7=BB=84.md=20about=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...15345円255円220円346円225円260円347円273円204円.md" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git "a/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" "b/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" index 82bf4f59e2..5b5e7a6c87 100644 --- "a/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" +++ "b/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" @@ -537,6 +537,29 @@ function findLength(nums1: number[], nums2: number[]): number { }; ``` +Rust: + +> 滚动数组 + +```rust +impl Solution { + pub fn find_length(nums1: Vec, nums2: Vec) -> i32 { + let (mut res, mut dp) = (0, vec![0; nums2.len()]); + + for n1 in nums1 { + for j in (0..nums2.len()).rev() { + if n1 == nums2[j] { + dp[j] = if j == 0 { 1 } else { dp[j - 1] + 1 }; + res = res.max(dp[j]); + } else { + dp[j] = 0; + } + } + } + res + } +} +```

AltStyle によって変換されたページ (->オリジナル) /