From dbbf6be3438053c82956c2034cdace8e83d5350c Mon Sep 17 00:00:00 2001 From: Soham Dey <115808276+IamSohamDey@users.noreply.github.com> Date: Mon, 17 Oct 2022 01:18:44 +0530 Subject: [PATCH] Create WordBreak.py This is the solution for the program of Word Break --- WordBreak.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 WordBreak.py diff --git a/WordBreak.py b/WordBreak.py new file mode 100644 index 0000000..d842300 --- /dev/null +++ b/WordBreak.py @@ -0,0 +1,12 @@ +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + + f = [False for i in range(len(s) + 1)] + f[0] = True + + for i in range(len(s)): + for j in range(i, len(s)): + if f[i] and s[i:j + 1] in wordDict: + f[j + 1] = True + + return f[len(s)]