11package com .fishercoder .solutions ;
22
33import java .util .List ;
4- import java .util .Set ;
54
65/**
76 * 139. Word Break
@@ -24,7 +23,7 @@ The wordDict parameter had been changed to a list of strings (instead of a set o
2423public class _139 {
2524
2625 public static class Solution1 {
27- /**this beats 70.46% submission. */
26+ /** this beats 70.46% submission. */
2827 public boolean wordBreak (String s , List <String > wordDict ) {
2928 int n = s .length ();
3029 boolean [] dp = new boolean [n + 1 ];
@@ -75,7 +74,7 @@ public static class Solution3 {
7574 * Added pruning, plus start from the end to check.
7675 * This beats 95.20% submissions.
7776 */
78- public boolean wordBreak (String s , Set <String > wordDict ) {
77+ public boolean wordBreak (String s , List <String > wordDict ) {
7978 int maxLen = Integer .MIN_VALUE ;
8079 for (String word : wordDict ) {
8180 maxLen = (word .length () > maxLen ) ? word .length () : maxLen ;
@@ -85,7 +84,8 @@ public boolean wordBreak(String s, Set<String> wordDict) {
8584 boolean [] dp = new boolean [n + 1 ];
8685 dp [0 ] = true ;
8786 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 ++) {
8989 if (!dp [i - lastWordLength ]) {
9090 continue ;
9191 }
0 commit comments