在数组中找出和为固定值的组合

alt text

alt text

在有重复数字的数组中找出和为固定值的组合

给出给定字符串中所有的回文子字符串

class Solution {
private:
vector<vector<string>> res;
vector<string> path;
     bool Ispalidro(const string & s,int start,int end){
        for(int i=start,j=end;i<j;i++,j--){
            if(s[i]!=s[j])
            return false;
        }
        return true;
     }
     void backTrack(const string &s,int startIndex){
        if(startIndex>=s.size())
        {
            res.push_back(path);
            return;
        }
     for(int i=startIndex;i<s.size();i++){
        if(Ispalidro(s,startIndex,i)){
            string str=s.substr(startIndex,i-startIndex+1);//真是抽象
            path.push_back(str);
            }
            else 
            {
                continue;
            }
        backTrack(s,i+1);
        path.pop_back();
     }
     }
public:

    vector<vector<string>> partition(string s) {
         backTrack(s,0);
         return res;
    }
};
posted on 2025-11-28 21:40  FAfa_C++  阅读(0)  评论(0)    收藏  举报