55
66/**
77 * 139. Word Break
8+ *
89 * Given a non-empty string s and a dictionary wordDict containing a list of non-empty words,
910 * determine if s can be segmented into a space-separated sequence of one or more dictionary words.
1011 * You may assume the dictionary does not contain duplicate words.
@@ -22,10 +23,8 @@ The wordDict parameter had been changed to a list of strings (instead of a set o
2223
2324public class _139 {
2425
25- public static class PureDPSolution {
26- /**
27- * This beats 70.10% submissions.
28- */
26+ public static class Solution1 {
27+ /**this beats 70.46% submission. */
2928 public boolean wordBreak (String s , List <String > wordDict ) {
3029 int n = s .length ();
3130 boolean [] dp = new boolean [n + 1 ];
@@ -42,9 +41,10 @@ public boolean wordBreak(String s, List<String> wordDict) {
4241 }
4342 }
4443
45- public static class ModifiedDPAndPruningSolution {
44+ public static class Solution2 {
4645 /**
47- * This beats 86.09% submissions.
46+ * Added pruning.
47+ * this beats 89.91% submissions.
4848 */
4949 public boolean wordBreak (String s , List <String > wordDict ) {
5050 int maxLen = Integer .MIN_VALUE ;
@@ -70,9 +70,10 @@ public boolean wordBreak(String s, List<String> wordDict) {
7070 }
7171 }
7272
73- public static class DPAndPruningSolution {
73+ public static class Solution3 {
7474 /**
75- * This beats 97.08% submissions.
75+ * Added pruning, plus start from the end to check.
76+ * This beats 95.20% submissions.
7677 */
7778 public boolean wordBreak (String s , Set <String > wordDict ) {
7879 int maxLen = Integer .MIN_VALUE ;
0 commit comments