File tree 3 files changed +49
-0
lines changed
solution/0100-0199/0139.Word Break
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -480,6 +480,24 @@ class Trie {
480
480
}
481
481
```
482
482
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
+
483
501
### ** ...**
484
502
485
503
```
Original file line number Diff line number Diff line change @@ -454,6 +454,24 @@ class Trie {
454
454
}
455
455
```
456
456
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
+
457
475
### ** ...**
458
476
459
477
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments