mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 0139.单词拆分.md about rust
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user