点击打开链接
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <limits>
#include <math.h>
#include <queue>
using namespace std;
class Solution {
public:
bool isPalindrome(string s)
{
int len=s.size();
if(len==0 || len==1) return true;
int i=0, j=len-1;
while (i<j) {
if(s[i++]!=s[j--]) return false;
}
return true;
}
void partition_helper(string s, vector<string> tmp, vector<vector<string>>& ret)
{
if(s.size()==0){
ret.push_back(tmp);
return;
}
for(int i=1;i<=s.size();i++){
string substr = s.substr(0,i);//第一个参数是起始下表位置,第二个是截取的字符个数。
if(isPalindrome(substr)){
int strlen = s.size();
tmp.push_back(substr); //典型回溯模版
partition_helper(s.substr(i, strlen-i), tmp, ret);
tmp.pop_back();
}
}
}
vector<vector<string>> partition(string s) {
vector< vector<string> >ret;
if(s.size()==0) return ret;
vector<string> tmp;
partition_helper(s, tmp, ret);
return ret;
}
};
int main()
{
return 0;
}