Advertisement
Guest User

Untitled

a guest
May 20th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1.  
  2. class Solution:
  3.     def wordBreak(self, s, wordDict):
  4.         if not s:
  5.            return False
  6.         if not len(wordDict):
  7.            return False
  8.         rightmosts, words = [0], set(wordDict)
  9.         for i in range(1, len(s) + 1):
  10.             for last_index in rightmosts:
  11.                 if s[last_index:i] in words:
  12.                     rightmosts.append(i)
  13.                     if i == len(s): return True
  14.                     break
  15.         return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement