-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path131.cpp
More file actions
48 lines (46 loc) · 842 Bytes
/
131.cpp
File metadata and controls
48 lines (46 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cctype>
using namespace std;
class Solution {
public:
vector<int> temppath,path,res;
vector<vector<string>> partition(string s) {
vector<vector<string >>res;
vector<string> temp;
dfs(res,temp,0,s);
return res;
}
void dfs(vector<vector<string>> &res,vector<string> &temp,int pos,string s)
{
if(pos==s.length())
res.push_back(temp);
for(int i=pos;i<s.length();i++)
{
if(ispar(s,pos,i))
{
temp.push_back(s.substr(pos,i-pos+1));
dfs(res,temp,i+1,s);
temp.pop_back();
}
}
}
bool ispar(string s,int i,int j)
{
while(i<j)
{
if(s[i]!=s[j])
return false;
i++;j--;
}
return true;
}
};