[LeetCode]---word-break
来源:互联网 发布:刷棒棒糖辅助软件 编辑:程序博客网 时间:2024/06/15 13:48
题目描述
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”.
分析
>设数组大小为N;初始化一个数组dp得 vector<bool> dp(N+1,false); dp[i]表示为字符串s[0...i-1]位置,能否由字典中的词组成,则dp[len]则为最终的解
代码如下
void isWordBreak(string &s,unordered_set<string> &dict, vector<bool> &dp){ for (unsigned long i = 1; i <= s.size(); ++i){ for (int j = i - 1; j >= 0; --j){ if(dp[j]&&dict.find(s.substr(j,i-j))!=dict.end()) dp[i]=true; } } }bool wordBreak(string&s, unordered_set<string> &dict) { const int N = s.size(); vector<bool> dp(N + 1, false); dp[0] = true; isWordBreak(s, dict, dp); 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
- 试题_(带分数)03
- 用jq实现无限轮播
- CCF CSP 压缩编码
- mysqldump: Couldn't execute 'SAVEPOINT sp'
- FFmpeg常用推流命令
- [LeetCode]---word-break
- 棋牌游戏服务器架构设计
- 这8种武器点亮程序员的个人品牌
- 趣写算法系列之--匈牙利算法
- Servlet 3之异步处理特性
- Comet & Jetty Continuations
- D. Jon and Orbs(概率dp)
- ZeroMQ:云计算时代最好的通讯库
- python中sklearn的支持向量机(Support Vector Machines)的说明地址