Skip to content

Commit d56c8a4

Browse files
Merge pull request PawanJaiswal08#108 from IamSohamDey/patch-4
Create WordBreak.py
2 parents a81f33a + dbbf6be commit d56c8a4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

WordBreak.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
3+
4+
f = [False for i in range(len(s) + 1)]
5+
f[0] = True
6+
7+
for i in range(len(s)):
8+
for j in range(i, len(s)):
9+
if f[i] and s[i:j + 1] in wordDict:
10+
f[j + 1] = True
11+
12+
return f[len(s)]

0 commit comments

Comments
 (0)