码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode – Refresh – Palindrome Partitioning I

时间:2015-03-21 17:02:38      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

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

 

LeetCode – Refresh – Palindrome Partitioning I

标签:

原文地址:http://www.cnblogs.com/shuashuashua/p/4355783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!