forked from Ayushsinhahaha/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisPalindrome.cpp
More file actions
35 lines (30 loc) · 820 Bytes
/
isPalindrome.cpp
File metadata and controls
35 lines (30 loc) · 820 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
bool ispalindrome(string str)
{
string per=str;
reverse(per.begin(),per.end());
return (per==str);
}
void func(string s,int index,vector<string>&path,vector<vector<string>>&ans)
{
if(index==s.size())
{
ans.push_back(path);
return;
}
for(int i=index;i<s.size();i++)
{
if(ispalindrome(s.substr(index,i-index+1)))
{
path.push_back(s.substr(index,i-index+1));
func(s,i+1,path,ans);
path.pop_back();
}
}
return;
}
vector<vector<string>> partition(string s) {
vector<vector<string>>ans;
vector<string>path;
func(s,0,path,ans);
return ans;
}