当前位置:Gxlcms > 数据库问题 > 力扣算法——139WordBreak【M】

力扣算法——139WordBreak【M】

时间:2021-07-01 10:21:17 帮助过:13人阅读

class Solution { 2 public: 3 bool wordBreak(string s, unordered_set<string> &dict) { 4 vector<string> wordDict; 5 unordered_set<string>dict; 6 for (auto a : wordDict) 7 dict.insert(a); 8 vector<bool>dp(s.size() + 1, false); 9 dp[0] = true;//边界 10 for(int i=0;i<dp.size();++i) 11 for(int j=0;j<i;++j) 12 if (dp[j] && dict.count(s.substr(j, i - j)))//状态转移方程 13 { 14 dp[i] = true; 15 break; 16 } 17 return dp.back(); 18 } 19 };

 

力扣算法——139WordBreak【M】

标签:基本   rdb   use   bre   另一个   segment   hand   情况   拆分   

人气教程排行