Skip to content

Commit

Permalink
Update 0139.单词拆分.md about rust
Browse files Browse the repository at this point in the history
  • Loading branch information
fwqaaq authored May 30, 2023
1 parent 842bafc commit 3e18a30
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions problems/0139.单词拆分.md
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 3e18a30

Please sign in to comment.