diff --git a/problems/0139.单词拆分.md b/problems/0139.单词拆分.md index 230942ef..402ce132 100644 --- a/problems/0139.单词拆分.md +++ b/problems/0139.单词拆分.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()] + } +} +```