• [LeetCode]Palindrome Partitioning


    Given a string s, partition s such that every substring of the partition is a palindrome.

    Return all possible palindrome partitioning of s.

    For example, given s = "aab",
    Return

      [
        ["aa","b"],
        ["a","a","b"]
      ]
    class Solution {
    private:
        vector<vector<string> > res;
    public:
        void DFS(string s, vector<string> &ans)
        {
            if(s.size()<1) 
            {
                res.push_back(ans);
                return;
            }
            for(int i=0;i<s.size();i++)
            {
                int start=0;
                int end=i;
                while(start<end)
                {
                    if(s[start]==s[end])
                    {
                      start++;
                      end--;
                    }
                     else break;
                }
                if(start>=end)
                {
                    ans.push_back(s.substr(0,i+1));
                    DFS(s.substr(i+1),ans);
                    ans.pop_back();
                }
            }
        }
        vector<vector<string>> partition(string s) {
            res.clear();
            vector<string> ans;
            DFS(s,ans);
            return res;
        }
    };
    

      

  • 相关阅读:
    丑数(摘)
    queue 之团队队列(摘)
    stack 集合栈计算机 (摘)
    反片语(map)
    stl的集合set——安迪的第一个字典(摘)
    stringstream函数(i o)
    T
    S
    R
    java面试题
  • 原文地址:https://www.cnblogs.com/Rosanna/p/3597364.html
Copyright © 2020-2023  润新知