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 1c9a838 commit 9ced22cCopy full SHA for 9ced22c
word-break/soobing2.ts
@@ -0,0 +1,26 @@
1
+/**
2
+ * 유형
3
+ * - dp (뒤쪽 단어를 쪼갤 수 있어야 전체를 쪼갤 수 있다.)
4
+ *
5
+ * 문제 설명
6
+ * - 문자열 s를 주어진 wordDict에 있는 단어로 쪼갤 수 있는가?
7
8
+ * 아이디어
9
+ * - dp[i] = s[i]로 시작하는 문자열이 wordDict에 있는 단어로 쪼갤 수 있는지 여부
10
+ */
11
+
12
+function wordBreak(s: string, wordDict: string[]): boolean {
13
+ const dp = new Array(s.length + 1).fill(false);
14
15
+ dp[s.length] = true;
16
17
+ for (let i = s.length - 1; i >= 0; i--) {
18
+ for (const word of wordDict) {
19
+ if (i + word.length <= s.length && s.slice(i, i + word.length) === word) {
20
+ dp[i] = dp[i + word.length];
21
+ }
22
+ if (dp[i]) break;
23
24
25
+ return dp[0];
26
+}
0 commit comments