Leetcode -- Word Break
来源:互联网 发布:优化驱动器有什么用 编辑:程序博客网 时间:2024/06/03 20:53
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"
.
class Solution {public: bool wordBreak(string s, unordered_set<string>& wordDict) { int n=s.size(); if(n==0) return 0; if(wordDict.count(s)>0) return 1; vector<bool> f(n,0); string cur,tmp; for(int i=n-1;i>=0;--i) { cur = s.substr(i); if(wordDict.count(cur)>0) f[i]=1; else { for(int j=i+1;j<n;++j) { tmp = s.substr(i,j-i); if(wordDict.count(tmp)>0&&f[j]) { f[i]=1; break; } } } } return f[0]; }};
0 0
- leetcode Word Break & Word Break ||
- Leetcode: Word Break
- [leetcode]Word Break
- [leetcode]Word Break II
- LeetCode:Word Break
- LeetCode:Word Break II
- Leetcode: Word Break II
- [LeetCode] Word Break
- [LeetCode] Word Break II
- LeetCode: Word Break
- leetcode之Word Break
- [LeetCode]Word Break II
- [LeetCode]Word Break
- leetcode-Word Break
- LeetCode 之 Word Break
- leetcode word break
- LeetCode | Word Break
- LeetCode | Word Break II
- eclipse4 以后,RCP 界面开发configurer.setShellStyle(SWT.MIN | SWT.CLOSE);不生效的解决方法
- 学习windows驱动(缓冲区溢出)
- CloudSuite之Web Search Benchmark环境搭建
- Microsoft Dynamics CRM4.0学习笔记(二)
- IOS SWIFT alte形式获取手机的相册和相机
- Leetcode -- Word Break
- Codevs 1427 特种部队
- DIY Ruby CPU 分析——Part III
- 记Flume-NG一些注意事项
- CentOS 6.5配置SSH免密码登录
- LeetCode---Binary Tree Zigzag Level Order Traversal
- Js实现对中文进行排序
- 用 SSH 连接两个数据库
- 修改命令行前缀 - Ubuntu配置笔记