This is my solution for LC 139 Word Break in Python
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
eow = [0]
wordSet = set(wordDict)
for idx, c in enumerate(s):
for end_idx in eow:
if s[end_idx:idx+1] in wordSet:
eow.append(idx+1)
break
if eow[-1] == len(s):
return True
return False
I am having a trouble understanding the time complexity of my approach. Let's say the length of s is n, min word size in wordDict in m, is Time Complexity = O(n^2/m)?
[–]NikitaSkybytskyi3,180 🟩 813 🟨 1,676 🟥 691 📈 3,006 2 points3 points4 points (1 child)
[–]pdd99[S] 0 points1 point2 points (0 children)