1
1
package com .fishercoder .solutions ;
2
2
3
3
import java .util .List ;
4
- import java .util .Set ;
5
4
6
5
/**
7
6
* 139. Word Break
@@ -24,7 +23,7 @@ The wordDict parameter had been changed to a list of strings (instead of a set o
24
23
public class _139 {
25
24
26
25
public static class Solution1 {
27
- /**this beats 70.46% submission. */
26
+ /** this beats 70.46% submission. */
28
27
public boolean wordBreak (String s , List <String > wordDict ) {
29
28
int n = s .length ();
30
29
boolean [] dp = new boolean [n + 1 ];
@@ -75,7 +74,7 @@ public static class Solution3 {
75
74
* Added pruning, plus start from the end to check.
76
75
* This beats 95.20% submissions.
77
76
*/
78
- public boolean wordBreak (String s , Set <String > wordDict ) {
77
+ public boolean wordBreak (String s , List <String > wordDict ) {
79
78
int maxLen = Integer .MIN_VALUE ;
80
79
for (String word : wordDict ) {
81
80
maxLen = (word .length () > maxLen ) ? word .length () : maxLen ;
@@ -85,7 +84,8 @@ public boolean wordBreak(String s, Set<String> wordDict) {
85
84
boolean [] dp = new boolean [n + 1 ];
86
85
dp [0 ] = true ;
87
86
for (int i = 1 ; i <= n ; i ++) {
88
- for (int lastWordLength = 1 ; lastWordLength <= i && lastWordLength <= maxLen ; lastWordLength ++) {
87
+ for (int lastWordLength = 1 ; lastWordLength <= i && lastWordLength <= maxLen ;
88
+ lastWordLength ++) {
89
89
if (!dp [i - lastWordLength ]) {
90
90
continue ;
91
91
}
0 commit comments