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 38fa297 commit 7bffe74Copy full SHA for 7bffe74
word-break/dev-jonghoonpark.md
@@ -0,0 +1,28 @@
1
+- 문제: https://leetcode.com/problems/word-break/
2
+- 풀이: https://algorithm.jonghoonpark.com/2024/02/28/leetcode-139
3
+
4
+```java
5
+class Solution {
6
+ public boolean wordBreak(String s, List<String> wordDict) {
7
+ boolean[] dp = new boolean[s.length() + 1];
8
+ dp[0] = true;
9
10
+ for (int i = 1; i <= s.length(); i++) {
11
+ for (String word : wordDict) {
12
+ if (i >= word.length()) {
13
+ int start = i - word.length();
14
+ if (dp[start] && s.startsWith(word, start)) {
15
+ dp[i] = true;
16
+ }
17
18
19
20
21
+ return dp[s.length()];
22
23
+}
24
+```
25
26
+### TC, SC
27
28
+s의 길이를 n 이라 하고, wordDict의 크기를 m 이라고 할 때, 시간복잡도는 `O(n * m)` 공간복잡도는 `O(n)` 이다.
0 commit comments