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 22
33import java .util .List ;
44
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-
235public class _139 {
246
257 public static class Solution1 {
26- /** this beats 70.46% submission. */
8+ /**
9+ * this beats 70.46% submission.
10+ */
2711 public boolean wordBreak (String s , List <String > wordDict ) {
2812 int n = s .length ();
2913 boolean [] dp = new boolean [n + 1 ];
@@ -85,7 +69,7 @@ public boolean wordBreak(String s, List<String> wordDict) {
8569 dp [0 ] = true ;
8670 for (int i = 1 ; i <= n ; i ++) {
8771 for (int lastWordLength = 1 ; lastWordLength <= i && lastWordLength <= maxLen ;
88- lastWordLength ++) {
72+ lastWordLength ++) {
8973 if (!dp [i - lastWordLength ]) {
9074 continue ;
9175 }
You can’t perform that action at this time.
0 commit comments