-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY0065.cpp
More file actions
31 lines (31 loc) · 886 Bytes
/
DAY0065.cpp
File metadata and controls
31 lines (31 loc) · 886 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
// 131. Palindrome Partitioning
class Solution {
public:
bool isPalindrome(string &s,int left,int right){
while(left<=right){
if(s[left]!=s[right]) return false;
left++;
right--;
}
return true;
}
void back_track(string &s,int start,vector<string>&temp,vector<vector<string>>&answer){
if(start==s.size()){
answer.push_back(temp);
return ;
}
for(int i=start;i<s.size();i++){
if(isPalindrome(s,start,i)){
temp.push_back(s.substr(start,i-start+1));
back_track(s,i+1,temp,answer);
temp.pop_back();
}
}
}
vector<vector<string>> partition(string s) {
vector<vector<string>>answer;
vector<string>temp;
back_track(s,0,temp,answer);
return answer;
}
};