Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bfff868

Browse files
authored
feat: add rust solution to lc problem: No.0139 (doocs#1720)
1 parent 7c610c0 commit bfff868

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

‎solution/0100-0199/0139.Word Break/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,24 @@ class Trie {
480480
}
481481
```
482482

483+
### **Rust**
484+
485+
```rust
486+
impl Solution {
487+
pub fn word_break(s: String, word_dict: Vec<String>) -> bool {
488+
let words: std::collections::HashSet<String> = word_dict.into_iter().collect();
489+
let mut f = vec![false; s.len() + 1];
490+
f[0] = true;
491+
for i in 1..=s.len() {
492+
for j in 0..i {
493+
f[i] |= f[j] && words.contains(&s[j..i]);
494+
}
495+
}
496+
f[s.len()]
497+
}
498+
}
499+
```
500+
483501
### **...**
484502

485503
```

‎solution/0100-0199/0139.Word Break/README_EN.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,24 @@ class Trie {
454454
}
455455
```
456456

457+
### **Rust**
458+
459+
```rust
460+
impl Solution {
461+
pub fn word_break(s: String, word_dict: Vec<String>) -> bool {
462+
let words: std::collections::HashSet<String> = word_dict.into_iter().collect();
463+
let mut f = vec![false; s.len() + 1];
464+
f[0] = true;
465+
for i in 1..=s.len() {
466+
for j in 0..i {
467+
f[i] |= f[j] && words.contains(&s[j..i]);
468+
}
469+
}
470+
f[s.len()]
471+
}
472+
}
473+
```
474+
457475
### **...**
458476

459477
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
impl Solution {
2+
pub fn word_break(s: String, word_dict: Vec<String>) -> bool {
3+
let words: std::collections::HashSet<String> = word_dict.into_iter().collect();
4+
let mut f = vec![false; s.len() + 1];
5+
f[0] = true;
6+
for i in 1..=s.len() {
7+
for j in 0..i {
8+
f[i] |= f[j] && words.contains(&s[j..i]);
9+
}
10+
}
11+
f[s.len()]
12+
}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /