leetcode---word-break---dp
来源:互联网 发布:python assert() 编辑:程序博客网 时间:2024/06/07 03:55
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) { int n = s.size(); vector<bool> dp(n+1, false); dp[0] = true; for(int i=0; i<n; i++) { string subs = s.substr(0, i+1); for(int j=0; j<=i; j++) { if(dp[j] && dict.count(subs)) dp[i+1] = true; subs = subs.substr(1, subs.size() - 1); } } return dp[n]; }};
阅读全文
0 0
- LeetCode Word Break (dp)
- Leetcode dp Word Break
- 【Leetcode】Word Break (DP)
- [leetcode][DP] Word Break
- [LeetCode.DP]Word Break ||
- LeetCode Word Break DP
- leetcode---word-break---dp
- LeetCode:Word Break(DP)
- LeetCode:Word Break II(DP)
- leetcode Word Break 字典树+dp
- [C++]LeetCode: 112 Word Break(DP)
- LeetCode 140. Word Break II (DP+DFS)
- [leetcode][DP][回溯] Word Break II
- [leetcode][DP][回溯] Word Break II
- LeetCode Word Break II DP+DFS
- Leetcode 139 - Word Break(线性dp)
- leetcode Word Break & Word Break ||
- Word Break ,dp
- input标签
- 解决eclipse中Errors running builder JavaScript Validator的问题
- MD5 加密
- 报错JedisConnectionException: Could not get a resource from the pool 已解决。(不是代码问题,Tomcat缓存问题)
- SQL注入学习三
- leetcode---word-break---dp
- 【Apollo源码分析】系列的第六部分【planning】
- 新疆网络赛 经验总结
- 最近任务栏清除app导致app不执行onDestory
- UCOS学习笔记
- 2017-09-09 LeetCode_015 3Sum
- Git学习笔记(8)----总结(常用命令清单)
- NUL与NULL的区别
- 2017.9.9 传送带 失败总结