Merge pull request #2112 from fwqaaq/patch-32

Update 0139.单词拆分.md about rust
This commit is contained in:
程序员Carl
2023-06-15 09:32:22 +08:00
committed by GitHub

View File

@ -496,7 +496,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">