LeeCode_139 Word Break
2016-02-18 10:06
309 查看
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 =
dict =
Return true because
For example, given
s =
"leetcode",
dict =
["leet", "code"].
Return true because
"leetcode"can be segmented as
"leet code".
class Solution { public: bool wordBreak(string s, unordered_set<string> &dict) { int n = (int)s.size(); vector<bool> dp(n + 1, false); dp[0] = true; for (int i = 0; i < n; i++) { if (dp[i]) { for (int len = 1; i + len - 1 < n; len++) if (dict.count(s.substr(i, len)) > 0) dp[i + len] = true; } } return dp ; } };
相关文章推荐
- JS之公共方法(通讯、正则、乘法)
- VMware vSphere 6.0 / vCloud 6.0 / Horizon 6.1 下载发布
- spoj ETF
- oracle如何 查询 创建 执行存储过程及游标的作用
- 笔记2,使用jQuery
- tomcat跨域访问
- 一个label里有个链接,点这个特别颜色的一些字,会执行一些操作
- VMware虚拟机NAT模式的具体配置
- oc强化day02内容
- Android系统架构的详细解析——很全面
- Eclipse中修改SVN用户名和密码方法
- Android系统移植(五)
- Windows安装运行Kafka
- EL表达式
- Android 软键盘和emoji表情切换方案,和微信几乎一样的体验
- 笔记1,认识jQuery
- Android LinearLayout及TextView的布局方式
- subversion安装和使用
- 《网络攻防技术与实践》学习指导
- 亚里士多德 - 上古时代的百科全书