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 742fe06cb4..0d88ba3681 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" @@ -496,7 +496,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()] + } +} +```