Skip to content

Commit

Permalink
Time: 155 ms (54.57%), Space: 79.9 MB (29.85%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Jan 22, 2023
1 parent 5be9fa7 commit e4282fa
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 0131-palindrome-partitioning/0131-palindrome-partitioning.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Solution {
public:
vector<vector<string>> ans;
bool chk(string s,int i,int j)
{
while(i<j)
{
if(s[i]==s[j])
{
i++;
j--;
continue;
}
else
{
return false;
}
}
return true;
}
void solve(string &s, int k, vector<string> &curr)
{
if(k==s.size())
{
ans.push_back(curr);
return;
}
for(int i=k;i<s.size();i++)
{
if(chk(s,k,i))
{
curr.push_back(s.substr(k,i-k+1));
solve(s,i+1,curr);
curr.pop_back();

}
}
}
vector<vector<string>> partition(string s) {
vector<string> curr;
solve(s,0,curr);
return ans;
}
};

0 comments on commit e4282fa

Please sign in to comment.