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 };

 

posted on 2015-03-25 08:18  keepshuatishuati  阅读(127)  评论(0编辑  收藏  举报