###### LeetCode-Word Break

Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

For example, given
s = “leetcode”,
dict = [“leet”, “code”].

Return true because “leetcode” can be segmented as “leet code”.

DP解法：

1.若t=s.substr(0,i)在字典中，则dp[i]=true;
2.若t=s.substr(0,i)不在字典中

 bool wordBreak(string s, unordered_set<string>& wordDict)
{

int n=s.length();
if(n==0)
{
return false;
}
vector<bool> bp(n+1,false);
for(int i=1;i<=n;++i)
{
string t=s.substr(0,i);
bp[i]=wordDict.find(t)!=wordDict.end()?true:false;
if(bp[i])
{
continue;
}
else
{
for(int j=1;j<i;++j)
{
if(bp[j])
{
string t1=s.substr(j,i-j);
bp[i]=wordDict.find(t1)!=wordDict.end()?true:false;
if(bp[i])
{
break;
}
}

}
}
}

return bp[n];
}

#### leetcode-Word Break

2013-11-24 20:20:39

#### Leetcode-Word Break

2017-11-30 22:10:07

#### *LeetCode-Word Break

2015-09-25 06:31:09

#### leetcode-Word Break II

2014-07-22 23:53:16

#### Leetcode-Word Break II

2015-07-06 17:26:40

#### LeetCode-Word Break II

2014-07-29 15:37:05

2013-08-22 21:14:02

#### LeetCode-Word Search

2013-08-20 10:20:30

2015-10-06 03:00:41

#### LeetCode-Word Pattern

2015-10-26 09:40:53

## 不良信息举报

LeetCode-Word Break