leetcode 131. Palindrome Partitioning

来源:互联网 发布:画网络拓扑图 app 编辑:程序博客网 时间:2024/06/07 02:02
class Solution {public:vector<vector<string>> partition(string s){if (s.empty()){return{};}process(0, s);return res;}private:vector<vector<string>> res;vector<string> temp;void process(int start, string& s){if (start == s.size()){res.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));process(i + 1, s);temp.pop_back();}}}bool isPalindrome(string &s, int start, int end){while (start <= end){if (s[start++] != s[end--]){return false;}}return true;}};

0 0