My clear C++ solution


  • 0
    F

    class Solution {
    private:
    vector<vector<string>> re;
    vector<string> temp;
    public:
    bool judge(string s){
    int head=0,tail=s.size()-1;
    while(head<tail){
    if(s[head++]!=s[tail--]) return false;
    }
    return true;
    }
    void helper(int start,string s){
    if(start==s.size()){
    re.push_back(temp);
    return;
    }
    for(int i=start;i<s.size();i++){
    string sub=s.substr(start,i-start+1);
    if(judge(sub)){
    temp.push_back(sub);
    helper(i+1,s);
    temp.pop_back();
    }else continue;
    }
    }
    vector<vector<string>> partition(string s) {
    helper(0,s);
    return re;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.