ITPub博客

首页 > > > [LeetCode] Palindrome Partitioning

[LeetCode] Palindrome Partitioning

作者:Ruiyuan Li 时间:2015-08-16 00:00:00 0 删除 编辑

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"]
  ]

解题思路:

题意为找出对字符串的所有划分,使得每个划分都是回文。用递归的方法做。

注意s.substr(i);方法,如果i等于s的长度,返回一个空字符串。若i大于s的长度,报错。

class Solution {
public:
    vector> partition(string s) {
        vector> result;
        
        vector item;
        
        helper(item, s, result);
        
        return result;
    }
    
    void helper(vector& item, string s, vector>& result){
        int len = s.length();
        if(len == 0 && item.size()>0){
            result.push_back(item);
            return;
        }
        for(int i=0; i


转载请注明: » [LeetCode] Palindrome Partitioning
<!-- -->

原文作者:;如有侵权,请联系管理员删除。

上一篇: 我觉得自己好傻
请登录后发表评论 登录
全部评论

注册时间:2020-05-21

  • 博文量
    495
  • 访问量
    4826