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+ Blind 75 - Word Break
3+ LeetCode Problem: https://leetcode.com/problems/word-break/
4+ ์๊ฐ๋ณต์ก๋ : O(n^2)
5+ ๊ณต๊ฐ๋ณต์ก๋ : O(n)
6+ ํ์ด : ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ์ ์ด์ฉํ ํ์ด
7+ ๋ฌธ์์ด s์ ๊ธธ์ด๋ฅผ n์ด๋ผ ํ ๋, dp[i]๋ฅผ s์ ์ฒ์๋ถํฐ i-1๋ฒ์งธ ๋ฌธ์๊น์ง์ ๋ถ๋ถ ๋ฌธ์์ด์ด
8+ ๋จ์ด ์ฌ์ ์ ์๋ ๋จ์ด๋ค๋ก ๊ตฌ์ฑ๋ ์ ์๋์ง๋ฅผ ๋ํ๋ด๋ ๋ถ๋ฆฌ์ธ ๊ฐ์ด๋ผ๊ณ ์ ์ํ๋ค.
9+ """
10+ from typing import List
11+ class Solution :
12+ def wordBreak (self , s : str , wordDict : List [str ]) -> bool :
13+ dp = [False ] * (len (s ) + 1 )
14+ dp [0 ] = True
15+
16+ word_set = set (wordDict )
17+ for i in range (1 , len (s ) + 1 ):
18+ for j in range (i ):
19+ if dp [j ] and s [j :i ] in word_set : # 0~j-1๊น์ง ๋ฌธ์์ด์ด ๋จ์ด์ฌ์ ์ ์๊ณ , j~i-1๊น์ง ๋ฌธ์์ด์ด ๋จ์ด์ฌ์ ์ ์๋ ๊ฒฝ์ฐ
20+ dp [i ] = True
21+ break
22+
23+ return dp [len (s )]
You canโt perform that action at this time.
0 commit comments