leetcode-131-分割回文串

class Solution {

public:

    vector<vector<string>> res;

    bool isHuiwen(string s) {

        for (int i = 0; i < s.length() / 2; i++) if (s[i] != s[s.length()- 1 - i]) return false;

        return true;

    }

    void helper(string s, vector<string> curres) {

        //string backS = s.substr(index);

        //if (s.length() == 0) return;

        

        //if (!isHuiwen(frontS)) return;

        

        //if (index > s.length()) return;

        for (int i = 1; i <= s.length(); i++) {

            string frontS = s.substr(0, i);

            if (isHuiwen(frontS)) {

                vector<string> nxtres = curres;

                nxtres.push_back(frontS);

                if(i == s.length()) res.push_back(nxtres);

                helper(s.substr(i), nxtres);

            }

        }

        return;

    }

    vector<vector<string>> partition(string s) {

        vector<string> temp = {};

        helper(s, temp);

        //vector<vector<string>> r(res.begin(), res.end());

        return res;

    }

};

发布了81 篇原创文章 · 获赞 0 · 访问量 1339

猜你喜欢

转载自blog.csdn.net/ChenD17/article/details/104317985
今日推荐