leetcode - Word Break
来源:互联网 发布:香港mac pro多少钱 编辑:程序博客网 时间:2024/06/16 00:09
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(std::string s, std::unordered_set<std::string> &dict) { int n = (int)s.size();std::vector<int> dp(n+1,0);dp[0] = 1;for(int i = 1; i <= n; i++){if(dp[i-1]){int index = i - 1;for(int j = index; j < n; j++){std::string str = s.substr(index,j-index+1);if(dict.count(str) > 0)dp[j+1] = 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
- java 遍历arrayList的四种方法
- linux权限管理命令
- 美元升值对中国资产价格的影响
- 接口、抽象类、修饰符解析
- 《数据结构》实验一:VC编程环境灵活应用
- leetcode - Word Break
- Java字节码运行浅析
- 泛型一些要记住的东西
- java操作智能卡 IC卡 连接pcsc读卡器 发送APDU指令 源代码 下载 jdk1.6满足要求 java语言 操作IC卡 操作智能卡
- day27,page50,total200
- 如何写一篇好的技术博客
- ListView Item 圆角问题
- 数据结构 实验3
- Shell批量重命名文件,使得在在移动设备中排序正确