File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ ๋ฌธ์ : ์ฃผ์ด์ง ๋ฌธ์์ด์ด ์ฌ์ ์ ์๋ ๋จ์ด๋ค๋ก ๊ตฌ์ฑ๋ ์ ์๋์ง ์ฌ๋ถ๋ฅผ ํ๋จํ๋ ์ฝ๋๋ฅผ ์์ฑํ์์ค.
3+ ํ์ด: ๋์ ํ๋ก๊ทธ๋๋ฐ(DP)์ ์ฌ์ฉํ์ฌ ๋ฌธ์์ด์ ๊ฐ ์์น๊น์ง ์ฌ์ ์ ์๋ ๋จ์ด๋ค๋ก ๊ตฌ์ฑ๋ ์ ์๋์ง ์ฌ๋ถ๋ฅผ ๊ธฐ๋กํฉ๋๋ค.
4+ ์๊ฐ๋ณต์ก๋: O(n*m) (n์ ๋ฌธ์์ด s์ ๊ธธ์ด, m์ ๋จ์ด ์ฌ์ ์ ๋จ์ด ์)
5+ ๊ณต๊ฐ๋ณต์ก๋: O(n)
6+ '''
7+
8+
9+ class Solution :
10+ def wordBreak (self , s : str , wordDict : List [str ]) -> bool :
11+ dp = [False for i in range (len (s ))]
12+ for i in wordDict :
13+ if i == s [:len (i )]:
14+ dp [len (i )- 1 ] = True
15+
16+ for i in range (1 , len (s )):
17+ if dp [i - 1 ] == True :
18+
19+ for j in wordDict :
20+ if i + len (j ) <= len (s ) and j == s [i :i + len (j )]:
21+ dp [i + len (j )- 1 ] = True
22+ return dp [len (s )- 1 ]
23+
You canโt perform that action at this time.
0 commit comments