From 83a87ab5ad2f1dd0f81f3e779921a46c15d979f8 Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年5月30日 16:28:09 +0800 Subject: [PATCH 1/5] =?UTF-8?q?Update=200279.=E5=AE=8C=E5=85=A8=E5=B9=B3?= =?UTF-8?q?=E6=96=B9=E6=95=B0.md=20about=20Rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...50345円271円263円346円226円271円346円225円260円.md" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" index f5b23d2636..d573695181 100644 --- "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" +++ "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" @@ -345,6 +345,29 @@ function numSquares(n: number): number { }; ``` +Rust: + +```rust +// 先遍历背包 +impl Solution { + pub fn num_squares(n: i32) -> i32 { + let n = n as usize; + let mut dp = vec![i32::MAX; n + 1]; + dp[0] = 0; + for i in 0..=n { + let mut j = 1; + loop { + match j * j> i { + true => break, + false => dp[i] = dp[i].min(dp[i - j * j] + 1), + } + j += 1; + } + } + dp[n] + } +} +```

From a2ff242303546243f606e717e34ff8d2965eeb9d Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年5月30日 18:30:14 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Update=200279.=E5=AE=8C=E5=85=A8=E5=B9=B3?= =?UTF-8?q?=E6=96=B9=E6=95=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...50345円271円263円346円226円271円346円225円260円.md" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" index d573695181..1a0b55c02a 100644 --- "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" +++ "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" @@ -369,6 +369,27 @@ impl Solution { } ``` +```rust +// 先遍历物品 +impl Solution { + pub fn num_squares(n: i32) -> i32 { + let (n, mut goods) = (n as usize, 1); + let mut dp = vec![i32::MAX; n + 1]; + dp[0] = 0; + loop { + if goods * goods> n { + break; + } + for j in goods * goods..=n { + dp[j] = dp[j].min(dp[j - goods * goods] + 1); + } + goods += 1; + } + dp[n] + } +} +``` +

From 46495a7753ebf1eb603891229375e06fc1f05a07 Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年5月30日 21:21:02 +0800 Subject: [PATCH 3/5] =?UTF-8?q?Update=200279.=E5=AE=8C=E5=85=A8=E5=B9=B3?= =?UTF-8?q?=E6=96=B9=E6=95=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...05250円345円271円263円346円226円271円346円225円260円.md" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" index 1a0b55c02a..71ab190637 100644 --- "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" +++ "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" @@ -331,6 +331,7 @@ var numSquares2 = function(n) { TypeScript: ```typescript +// 先遍历物品 function numSquares(n: number): number { const goodsNum: number = Math.floor(Math.sqrt(n)); const dp: number[] = new Array(n + 1).fill(Infinity); @@ -345,6 +346,20 @@ function numSquares(n: number): number { }; ``` +```rust +// 先遍历背包 +function numSquares(n: number): number { + const dp = Array(n + 1).fill(Infinity) + dp[0] = 0; + for(let i = 1; i <= n; i++){ + for(let j = 1; j * j <= i; j++){ + dp[i] = Math.min(dp[i], dp[i -j * j] + 1) + } + } + return dp[n] +}; +``` + Rust: ```rust From 3e18a30e36375046900278f7f09dc3ed53aa766f Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年5月30日 22:15:23 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Update=200139.=E5=8D=95=E8=AF=8D=E6=8B=86?= =?UTF-8?q?=E5=88=86.md=20about=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...225円350円257円215円346円213円206円345円210円206円.md" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git "a/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" "b/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" index 230942ef02..402ce132cf 100644 --- "a/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" +++ "b/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" @@ -464,7 +464,24 @@ function wordBreak(s: string, wordDict: string[]): boolean { }; ``` +Rust: +```rust +impl Solution { + pub fn word_break(s: String, word_dict: Vec) -> bool { + let mut dp = vec![false; s.len() + 1]; + dp[0] = true; + for i in 1..=s.len() { + for j in 0..i { + if word_dict.iter().any(|word| *word == s[j..i]) && dp[j] { + dp[i] = true; + } + } + } + dp[s.len()] + } +} +```

From 08823a26309c0bf87ecb90f680694f87255513bd Mon Sep 17 00:00:00 2001 From: rosethorn999 <24700793+rosethorn999@users.noreply.github.com> Date: 2023年5月30日 12:44:16 -0700 Subject: [PATCH 5/5] chore: Missing language name --- "problems/0383.350円265円216円351円207円221円344円277円241円.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/problems/0383.350円265円216円351円207円221円344円277円241円.md" "b/problems/0383.350円265円216円351円207円221円344円277円241円.md" index c7469d65bf..e74cdf71fd 100644 --- "a/problems/0383.350円265円216円351円207円221円344円277円241円.md" +++ "b/problems/0383.350円265円216円351円207円221円344円277円241円.md" @@ -146,6 +146,7 @@ class Solution { ``` +Python: (版本一)使用数组 ```python class Solution: @@ -210,7 +211,6 @@ class Solution: class Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: return all(ransomNote.count(c) <= magazine.count(c) for c in set(ransomNote)) - ``` Go:

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