-
Notifications
You must be signed in to change notification settings - Fork 0
/
leet_code_118.py
17 lines (16 loc) · 924 Bytes
/
leet_code_118.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#https://leetcode.com/problems/word-break/
#Word Break
#Given a string s and a dictionary of strings wordDict, return true if s can be segmented
#into a space-separated sequence of one or more dictionary words.
#Note that the same word in the dictionary may be reused multiple times in the segmentation.
#Input: s = "applepenapple", wordDict = ["apple","pen"]
#Output: true
#Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
#Note that you are allowed to reuse a dictionary word.
#Input: s = "leetcode", wordDict = ["leet","code"]
#Output: true
##Explanation: Return true because "leetcode" can be segmented as "leet code".
#Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
#Output: false
'True' if max([i+max(list(map(len,wordDict))) for i in ([i.start() for
i in re.finditer('apple', s)]+[i.start() for i in re.finditer('pen', s)])])==len(s) else 'False'