We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 70b935d commit 0310c80Copy full SHA for 0310c80
โword-break/yyyyyyyyyKim.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def wordBreak(self, s: str, wordDict: List[str]) -> bool:
3
+
4
+ # DP
5
+ dp = [False]*(len(s)+1)
6
+ dp[0] = True # ๋น๋ฌธ์์ด์ ๋จ์ด์์ด๋ ๋ง๋ค ์ ์์(True)
7
8
+ # i : s์ i๋ฒ์งธ ๋ฌธ์
9
+ for i in range(1,len(s)+1):
10
+ # j : ๋จ์ด ์๋ฅด๋ ์์์์น. s[:j]๊ฐ wordDict์ ์๊ณ , s[j:i]๊ฐ wordDict์ ์๋์ง ํ์ธ.
11
+ for j in range(i):
12
+ if dp[j] and s[j:i] in wordDict:
13
+ dp[i] = True # s[i]๊น์ง ์๋ฅผ ์ ์์(True)
14
+ break # ์๋ฅผ ์ ์์ผ๋๊น ๋ ๋ณผ ํ์ ์์
15
16
+ return dp[len(s)]
0 commit comments