Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s ="aab",
Return
[ ["aa","b"], ["a","a","b"] ]
class Solution { public: bool ispaili(string s) { int len = s.length(); for (int i = 0, j = len - 1; j > i; i++, j--) { if (s[i] != s[j]) return false; } return true; } void dfs(string s, int pos, vector<vector<string>>& vecvec, vector<string> vec) { if (pos>= s.size()) { vecvec.push_back(vec); return ; } for (int i = 1; i <=s.size() - pos; i++) { string substr = s.substr(pos, i); if (ispaili(substr)) { vec.push_back(substr); dfs(s, pos + i, vecvec, vec); vec.pop_back(); } //dfs(s, pos + i, vecvec, vec); } //dfs(s, pos + 1, vecvec,vec); } vector<vector<string>> partition(string s) { vector<vector<string>> vecvec; vector<string> vec; dfs(s, 0, vecvec,vec); return vecvec; } };