首页 > 其他 > 详细

LeetCode – Refresh – Word Break

时间:2015-03-25 08:54:48      阅读:121      评论:0      收藏:0      [点我收藏+]

Differentiate it with Palindrome min cut!!!!!!!!!

 1 class Solution {
 2 public:
 3     bool wordBreak(string s, unordered_set<string> &dict) {
 4         int len = s.size();
 5         if (len == 0) return false;
 6         vector<bool> dp(len+1, false);
 7         dp[0] = true;
 8         for (int i = 1; i <= len; i++) {
 9             for (int j = i-1; j >= 0; j--) {
10                 if (dp[j] && dict.find(s.substr(j, i-j)) != dict.end()) {
11                     dp[i] = true;
12                     
13                 }
14             }
15         }
16         return dp[len];
17     }
18 };

 

LeetCode – Refresh – Word Break

原文:http://www.cnblogs.com/shuashuashua/p/4364643.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!