Skip to content

Commit c2e75c0

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 139_Word_Break.java
1 parent 3c6ed62 commit c2e75c0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean wordBreak(String s, List<String> wordDict) {
3+
boolean[] dp = new boolean[s.length() + 1];
4+
dp[0] = true;
5+
6+
for (int i = 1; i <= s.length(); i++) {
7+
for (int j = 0; j < i; j++) {
8+
if (dp[j] && wordDict.contains(s.substring(j, i))) {
9+
dp[i] = true;
10+
break;
11+
}
12+
}
13+
}
14+
15+
return dp[s.length()];
16+
}
17+
}

0 commit comments

Comments
 (0)