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 bc2973c commit 2529897Copy full SHA for 2529897
0139-word-break/0139-word-break.kt
@@ -0,0 +1,30 @@
1
+class Solution {
2
+ fun wordBreak(s: String, wordDict: List<String>): Boolean {
3
+ val n = s.length
4
+ val isPossible = BooleanArray(n)
5
+ isPossible[0] = true
6
+
7
+ for (i in 0 until n) {
8
+ if (!isPossible[i]) {
9
+ continue
10
+ }
11
12
+ for (word in wordDict) {
13
+ val end = i + word.length
14
+ if (end > n) {
15
16
17
+ if (s.substring(i, end) != word) {
18
19
20
21
+ if (end == n) {
22
+ return true
23
24
+ isPossible[end] = true
25
26
27
28
+ return false
29
30
+}
0 commit comments