leetcode 139. Word Break(dp,字典匹配)
来源:互联网 发布:windows木马编程 编辑:程序博客网 时间:2024/06/06 14:11
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"
.
分析:
ac代码:
class Solution {
public:
bool wordBreak(string s, unordered_set<string>& wordDict) {
int i,j,L=s.length();
bool word[L+1];
for(i=1;i<=L;i++)
word[i]=false;
word[0]=true;
for(i=1;i<=L;i++)
{
for(j=i-1;j>=0;j--)
{
if(word[j]&&wordDict.find(s.substr(j,i-j))!=wordDict.end())
{
word[i]=true;
break;
}
}
}
return word[L];
}
};
- leetcode 139. Word Break(dp,字典匹配)
- leetcode Word Break 字典树+dp
- LeetCode:Word Break(DP)
- LeetCode Word Break (dp)
- Leetcode dp Word Break
- 【Leetcode】Word Break (DP)
- [leetcode][DP] Word Break
- [LeetCode.DP]Word Break ||
- LeetCode Word Break DP
- leetcode---word-break---dp
- [LeetCode]Word Break 字典树
- LeetCode:Word Break II(DP)
- Leetcode 139 - Word Break(线性dp)
- 140. Word Break II(dp,字典匹配,并输出所有匹配结果,即保存dp路径)(继续理解,重刷)
- 139. Word Break(dp)
- LeetCode 139. Word Break
- [LeetCode]139.Word Break
- [leetcode] 139.Word Break
- 5 分钟上手 ECharts
- linux 查看性能消耗命令
- SpringMVC原理
- 用java实现猜数游戏(幸运猜猜猜)
- eslipse 开启报错A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in orde
- leetcode 139. Word Break(dp,字典匹配)
- 初级前端自学react-native,必备知识点(ES6+ReactJS+flexbox)
- SpringMVC框架搭建
- Q14--顺时针打印矩阵
- Linux多线程编程(三)线程同步之互斥量
- 微信小程序-菜谱APP
- 仿支付宝提现选择到账银行卡页面实现
- drawable 回收机制参考
- android计时器延时启动活动