1 class Solution {
 2 public:
 3     bool isP(string s) {
 4         int start = 0, end = s.size()-1;
 5         while (start < end) {
 6             if (s[start++] != s[end--]) return false;
 7         }
 8         return true;
 9     }
10     void getP(vector<vector<string> > &result, vector<string> current, string s, int index) {
11         if (index == s.size()) {
12             result.push_back(current);
13             return;
14         }
15         for (int i = index; i < s.size(); i++) {
16             if (isP(s.substr(index, i-index+1))) {
17                 current.push_back(s.substr(index, i-index+1));
18                 getP(result, current, s, i+1);
19                 current.pop_back();
20             }
21         }
22     }
23     vector<vector<string>> partition(string s) {
24         vector<vector<string> > result;
25         getP(result, vector<string> (), s, 0);
26         return result;
27     }
28 };

 

posted on 2015-03-21 16:36  keepshuatishuati  阅读(118)  评论(0编辑  收藏  举报