fork download
  1. def word_break(s, wordDict):
  2. n = len(s)
  3. dp = [False] * (n + 1)
  4. dp[0] = True
  5.  
  6. for i in range(1, n + 1):
  7. for j in range(i):
  8. if dp[j] and s[j:i] in wordDict:
  9. dp[i] = True
  10. break
  11.  
  12. return dp[n]
  13.  
  14. # Example usage:
  15. s = "a"
  16. wordDict = ["aaa"]
  17.  
  18. if word_break(s, wordDict):
  19. print("1")
  20. else:
  21. print("0")
  22.  
Success #stdin #stdout 0.05s 63444KB
stdin
Standard input is empty
stdout
0