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 f665acb commit 1e91ae8Copy full SHA for 1e91ae8
word-break/gmlwls96.kt
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ /**
3
+ * 시간 : O(s^2*w), 공간 : O(s)
4
+ * */
5
+ fun wordBreak(s: String, wordDict: List<String>): Boolean {
6
+ val dp = BooleanArray(s.length + 1)
7
+ dp[0] = true
8
+ for (i in 1..s.length) {
9
+ val subS = s.substring(0, i)
10
+ val endWord = wordDict.firstOrNull { subS.endsWith(it) }
11
+ if (endWord != null) {
12
+ dp[i] = dp[i - endWord.length]
13
+ }
14
15
+ return dp[s.length]
16
17
+}
0 commit comments