LeetCode之Word Break
来源:互联网 发布:windows exe elf 编辑:程序博客网 时间:2024/06/05 04:07
/*动态规划法。设dp[i]表示s[0...i]是否满足题意,则有dp[i] = {dp[k] && s.substr(k, i-k)}(k=0...i-1,有一个为真即可)。*/class Solution {public: bool wordBreak(string s, unordered_set<string>& wordDict) { if(s.empty()) return true; vector<int> dp(s.size()+1, 0);dp[0] = 1; for(int i = 1; i <= s.size(); ++i){ for(int k = i-1; k >= 0; --k){ if(dp[k] && wordDict.find(s.substr(k, i-k)) != wordDict.end()){ dp[i] = 1; break; } } } return dp[s.size()]; }};
0 0
- leetcode之Word Break
- LeetCode 之 Word Break
- leetcode之Word Break
- leetcode之Word Break
- leetcode之Word Break
- leetcode之Word Break
- LeetCode之Word Break
- leetcode之Word-break
- leetcode之Word Break II
- leetcode之Word Break II
- LeetCode之Word Break II
- leetcode Word Break & Word Break ||
- Leetcode刷题之Word Break
- LeetCode OJ 之 Word Break (断词)
- Leetcode: Word Break
- [leetcode]Word Break
- [leetcode]Word Break II
- LeetCode:Word Break
- HDU-1867-A + B for you again
- 文章标题
- A20平台调试GPS模块
- diffrence between [[[[UIApplication sharedApplication] delegate] window] and [[UIApplication sharedA
- 白雪歌送武判官归京
- LeetCode之Word Break
- shiro使用手册
- 使用Markdown编辑器写博客
- Souvenir
- 凉州馆中与诸判官夜集
- 【转载】MYSQL对时间的处理
- 最长回文子串长度
- Android 中parcelable 和 parcel
- 复制粘贴测试