首页 > 其他 > 详细

LeetCode – Refresh – Palindrome Partitioning I

时间:2015-03-21 17:01:15      阅读:333      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!