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 ab5f639 commit 8a2b330Copy full SHA for 8a2b330
word-break/delight010.swift
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ func wordBreak(_ s: String, _ wordDict: [String]) -> Bool {
3
+ var wordArray = Array(repeating: false, count: s.count + 1)
4
+ wordArray[0] = true
5
+ for i in 1...s.count {
6
+ for j in 0..<i {
7
+ if wordArray[j] {
8
+ let startIndex = s.index(s.startIndex, offsetBy: j)
9
+ let endIndex = s.index(s.startIndex, offsetBy: i)
10
+ let word = String(s[startIndex..<endIndex])
11
+ if wordDict.contains(word) {
12
+ wordArray[i] = true
13
+ }
14
15
16
17
+ return wordArray[s.count]
18
19
+}
20
+
0 commit comments