Leetcode:Word Break
来源:互联网 发布:c语言用户标识符的 编辑:程序博客网 时间:2024/04/27 16:20
Word Break:
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> &dict) { // Note: The Solution object is instantiated only once and is reused by each test case. int n = (int)s.size();vector<bool> dp(n + 1, false);dp[0]=true;for(int i=1;i<=n;i++){if(dp[i-1]){int idx=i-1;for(int j=idx+1;j<=n;j++){string cur=s.substr(idx,j-idx);if(dict.count(cur)>0)dp[j]=true;}}}return dp[n];}};
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
- 7种形式的Android Dialog使用举
- codeblocks wxWighets环境配置
- 读懂xlinx ise综合报告
- 大整数乘法 多组输入
- 6.QT信号和槽
- Leetcode:Word Break
- samba服务器的安装
- 第十六周OJ——3 相同数字
- android 关于视频取某时间段的帧转化为bitmap后循环播出问题
- 常立志,不如立长志
- 第十六周OJ——4 奇数因子
- UVA10305 Ordering Tasks【DFS】【拓扑排序】
- Naive and Silly Muggles(计算几何 判断点是否在三点形成的最小圆内)
- HDOJ 5058 So easy