LeetCode 每日一题 131. 分割回文串 dfs
发布日期:2021-05-08 02:34:34 浏览次数:11 分类:原创文章

本文共 710 字,大约阅读时间需要 2 分钟。

分析

dfs()整个字符串即可。

C++ 代码

class Solution {public:    int n;    vector<vector<string>> ans;    bool check(string s)    //判断当前字符串是否为回文串    {        return s==string(s.rbegin(),s.rend());    }    void dfs(int u,vector<string> &v,string s)  //当前下标 当前字符串数组 字符串s    {        if(u==n){            ans.push_back(v);            return ;        }        string temp;        for(int i=u;i<n;i++)        {            temp+=s[i];            if(check(temp))            {                v.push_back(temp);                dfs(i+1,v,s);                v.pop_back();            }        }    }    vector<vector<string>> partition(string s) {        n=s.size();        vector<string> v;        dfs(0,v,s);        return ans;    }};
上一篇:十七、MySQL触发器(创建、删除、查看)详解
下一篇:IPv6数据报详解

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年04月10日 17时02分52秒