Update 0139.单词拆分.md about rust

This commit is contained in:
fwqaaq
2023-05-30 22:15:23 +08:00
committed by GitHub
parent 842bafc238
commit 3e18a30e36

View File

@ -464,7 +464,24 @@ function wordBreak(s: string, wordDict: string[]): boolean {
};
```
Rust:
```rust
impl Solution {
pub fn word_break(s: String, word_dict: Vec<String>) -> 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()]
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">