leetcode 139 Word Break(阿里测试岗笔试题)
2015-10-18 19:57
387 查看
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>& wordDict) { vector<bool> qie(s.length()+1,false); qie[0]=true; for(int i=1;i<s.length()+1;++i){ for(int j=i-1;j>=0;--j) { if(qie[j]&&wordDict.find(s.substr(j,i-j))!=wordDict.end()){ qie[i]=true; break; } } } return qie[s.length()]; } };
相关文章推荐
- 组合模式
- IOS开发—IB_Designable & IBInspectable介绍
- C++STL学习(6)其他容器(string,array,hashtable等)
- ImageLoader配置信息
- Objective-C Foundation框架实践——NSDictionary(一)
- FZU 2150 Fire Game(bfs)
- 第六周
- 【PAT】1037. Magic Coupon (25)
- 【cisco实验】练习 2.3.8: 配置基本交换机管理
- 小练习1
- Makefile
- 【VB】输出数据和输入数据
- hdu 2896 病毒侵袭 ac自动机
- CentOS配置VSFTP服务器
- 自考小总—学习思想升华
- Bug的严重程度、优先级如何定义
- linux文件权限
- 【VB】变量、常量、运算符与表达式
- hdu5505 GT and numbers
- 30多年程序员生涯经验总结