File tree Expand file tree Collapse file tree 1 file changed +4
-20
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +4
-20
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .util .List ;
4
4
5
- /**
6
- * 139. Word Break
7
- *
8
- * Given a non-empty string s and a dictionary wordDict containing a list of non-empty words,
9
- * determine if s can be segmented into a space-separated sequence of one or more dictionary words.
10
- * You may assume the dictionary does not contain duplicate words.
11
-
12
- For example, given
13
- s = "leetcode",
14
- dict = ["leet", "code"].
15
-
16
- Return true because "leetcode" can be segmented as "leet code".
17
-
18
- UPDATE (2017/1/4):
19
- The wordDict parameter had been changed to a list of strings (instead of a set of strings).
20
- Please reload the code definition to get the latest changes.
21
- */
22
-
23
5
public class _139 {
24
6
25
7
public static class Solution1 {
26
- /** this beats 70.46% submission. */
8
+ /**
9
+ * this beats 70.46% submission.
10
+ */
27
11
public boolean wordBreak (String s , List <String > wordDict ) {
28
12
int n = s .length ();
29
13
boolean [] dp = new boolean [n + 1 ];
@@ -85,7 +69,7 @@ public boolean wordBreak(String s, List<String> wordDict) {
85
69
dp [0 ] = true ;
86
70
for (int i = 1 ; i <= n ; i ++) {
87
71
for (int lastWordLength = 1 ; lastWordLength <= i && lastWordLength <= maxLen ;
88
- lastWordLength ++) {
72
+ lastWordLength ++) {
89
73
if (!dp [i - lastWordLength ]) {
90
74
continue ;
91
75
}
You can’t perform that action at this time.
0 commit comments