We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 133cd80 commit 51813d3Copy full SHA for 51813d3
word-break/sora0319.java
@@ -0,0 +1,19 @@
1
+public 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 n = 1; n <= s.length(); n++) {
7
+ for (String word : wordDict) {
8
+ if (n >= word.length() && s.substring(n - word.length(), n).equals(word)) {
9
+ dp[n] = dp[n - word.length()];
10
+ }
11
+ if (dp[n]) {
12
+ break;
13
14
15
16
17
+ return dp[s.length()];
18
19
+}
0 commit comments