Skip to content

Commit 04da4df

Browse files
refactor 139
1 parent 27e7f7d commit 04da4df

File tree

1 file changed

+4
-20
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-20
lines changed

src/main/java/com/fishercoder/solutions/_139.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,12 @@
22

33
import 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-
235
public 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
}

0 commit comments

Comments
 (0)