lintcode:Word Break
来源:互联网 发布:网络规划设计师视频 编辑:程序博客网 时间:2024/05/21 00:18
Given a string s and a dictionary of words dict, determine if s can be break into a space-separated sequence of one or more dictionary words.
设res[i]表示s的前i个数字母能否分拆后在dict中找到。
则
如果,则res[i]=true;
class Solution {public: /** * @param s: A string s * @param dict: A dictionary of words dict */ bool wordBreak(string s, unordered_set<string> &dict) { // write your code here int len=s.size(); if(len==0){ return true; } if(dict.size()==0){ return false; } int maxLen=0; for(string str:dict){ if(str.size()>maxLen){ maxLen=str.size(); } } vector<bool> res(len+1,false); res[0]=true; for(int i=1;i<=len;i++){ for(int j=i-1;j>=0;j--){ if(i-j>maxLen){ break; } bool flag=res[j]&& dict.find(s.substr(j,i-j))!=dict.end(); if(flag){ res[i]=true; break; } } } return res[len]; }};
0 0
- lintcode:Word Break
- LintCode: Word Break
- lintcode:Word Break
- LintCode Word Break II
- Word Break--lintcode
- Word-break:break-word
- Word Break && Word Break ||
- word-break
- Word Break
- Word Break
- Word Break
- word break
- Word Break
- Word Break
- Word Break
- Word Break
- Word Break
- Word Break
- SQLServer:定时作业的设置方法
- PHp向文件中写入数据
- 二维RMQ模板
- HDU 1281 棋盘游戏(二分图匹配)
- 独立安装WAMP
- lintcode:Word Break
- C语言多线程编程基础
- Programming Language Rankings——http://githut.info/
- Python -- 字符串大小写转换
- iOS 视频直播
- ExtJS 基础学习-1
- 错误:CGContextSetStrokeColorWithColor: invalid context 0x0
- Linux下新系统调用sync_file_range提高数据sync的效率
- pull解析过程