From 73590631ec3e17e727cca5a56024a07967946668 Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年5月27日 18:49:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Update=200518.=E9=9B=B6=E9=92=B1=E5=85=91?= =?UTF-8?q?=E6=8D=A2II.md=20=E4=BC=98=E5=8C=96=20Rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...351円222円261円345円205円221円346円215円242円II.md" | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git "a/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" "b/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" index c208754f77..8da351148b 100644 --- "a/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" +++ "b/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" @@ -282,17 +282,18 @@ func change(amount int, coins []int) int { Rust: ```rust -pub fn change(amount: i32, coins: Vec) -> i32 { - let amount = amount as usize; - let coins = coins.iter().map(|&c|c as usize).collect::>(); - let mut dp = vec![0usize; amount + 1]; - dp[0] = 1; - for i in 0..coins.len() { - for j in coins[i]..=amount { - dp[j] += dp[j - coins[i]]; +impl Solution { + pub fn change(amount: i32, coins: Vec) -> i32 { + let amount = amount as usize; + let mut dp = vec![0; amount + 1]; + dp[0] = 1; + for coin in coins { + for j in coin as usize..=amount { + dp[j] += dp[j - coin as usize]; + } } + dp[amount] } - dp[amount] as i32 } ``` From b76f5b6bffc6f53d81c7afdd6f05853f0577d68e Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年5月27日 23:14:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Update=200377.=E7=BB=84=E5=90=88=E6=80=BB?= =?UTF-8?q?=E5=92=8C=E2=85=A3.md=20=E4=BC=98=E5=8C=96=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...220円210円346円200円273円345円222円214円342円205円243円.md" | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git "a/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" "b/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" index ee65972371..ec57906087 100644 --- "a/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" +++ "b/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" @@ -253,16 +253,17 @@ Rust ```Rust impl Solution { pub fn combination_sum4(nums: Vec, target: i32) -> i32 { - let mut dp = vec![0; target as usize + 1]; + let target = target as usize; + let mut dp = vec![0; target + 1]; dp[0] = 1; - for i in 1..=target as usize { - for &j in nums.iter() { - if i as i32>= j { - dp[i] += dp[i- j as usize]; + for i in 1..=target { + for &n in &nums { + if i>= n as usize { + dp[i] += dp[i - n as usize]; } } } - return dp[target as usize]; + dp[target] } } ``` From 824ce31f87024fb4d7cc4e4fccdb9c56a761d0cb Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年5月27日 23:28:33 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Update=200070.=E7=88=AC=E6=A5=BC=E6=A2=AF?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E8=83=8C=E5=8C=85=E7=89=88=E6=9C=AC.md=20abo?= =?UTF-8?q?ut=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...14345円214円205円347円211円210円346円234円254円.md" | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git "a/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" "b/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" index 8f8bc9a649..5dde64098d 100644 --- "a/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" +++ "b/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" @@ -225,8 +225,25 @@ function climbStairs(n: number): number { }; ``` +Rust: - +```rust +impl Solution { + pub fn climb_stairs(n: i32) -> i32 { + let (n, m) = (n as usize, 2); + let mut dp = vec![0; n + 1]; + dp[0] = 1; + for i in 1..=n { + for j in 1..=m { + if i>= j { + dp[i] += dp[i - j]; + } + } + } + dp[n] + } +} +```

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