File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean wordBreak (String s , List <String > wordDict ) {
3+ /**
4+ 1.๋ฌธ์ : s ๊ฐ wordDict ๋ก ์ชผ๊ฐ์ง ์ ์๋์ง true/false return
5+ 2.์กฐ๊ฑด
6+ - s ์๋ wordDict ๊ฐ ์ฌ๋ฌ๋ฒ ๋์ฌ ์ ์์.
7+ - s.length() ์ต์ = 1, ์ต๋ 300
8+ - wordDict.size() ์ต์ 1, ์ต๋ 1000
9+ - ํ ๋จ์ด ๊ธธ์ด ์ต์=1, ์ต๋ = 20
10+ - ๋ชจ๋ ์๋ฌธ์. ๋ชจ๋ wordDict ๊ฐ์ unique
11+ 3.ํ์ด
12+ - i๋ฒ์งธ๊น์ง ๋ฌธ์์ด์ ๋ง๋ค ์ ์๋์ง check
13+ */
14+
15+ int n = s .length ();
16+ boolean [] dp = new boolean [n +1 ];
17+
18+ dp [0 ] = true ; //๋น ๋ฌธ์์ด์ธ ๊ฒฝ์ฐ
19+
20+ for (int i = 1 ; i < n +1 ; i ++) {
21+ for (int j = 0 ; j < i ; j ++) {
22+ String subStr = s .substring (j , i );
23+ //์๋จ๊ณ ๋ชจ๋ ๋ง๋ค ์ ์๊ณ && wordDict์ ์กด์ฌํ๋์ง ์ฒดํฌ
24+ if (dp [j ] && wordDict .contains (subStr )) {
25+ dp [i ] = true ;
26+ break ;
27+ }
28+ }
29+ }
30+ return dp [n ];
31+ }
32+ }
You canโt perform that action at this time.
0 commit comments