Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2112 from fwqaaq/patch-32
Browse files Browse the repository at this point in the history
Update 0139.单词拆分.md about rust
  • Loading branch information
youngyangyang04 authored Jun 15, 2023
2 parents 7725a38 + 3e18a30 commit 2d95c77
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 @@ -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">
Expand Down

0 comments on commit 2d95c77

Please sign in to comment.