[leetcode]Palindrome Partitioning
来源:互联网 发布:emacs for mac 编辑:程序博客网 时间:2024/06/18 09:32
题目描述:
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 {public: vector<vector<string>> partition(string s) { vector<vector<string>> result; vector<string> part; dfs(result,part,s,0); return result; } void dfs(vector<vector<string>> &result,vector<string> &part,string &s,int start){ if(start==s.length()){ result.push_back(part); return; } for(int i=start;i<s.length();i++){ if(isPalindrome(s,start,i)){ part.push_back(s.substr(start,i-start+1)); dfs(result,part,s,i+1); part.pop_back(); } } } bool isPalindrome(string &s,int start,int end){ while(start<end){ if(s[start]!=s[end])return false; start++; end--; } return true; }};
0 0
- 【leetcode】Palindrome Partitioning && Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning && Palindrome Partitioning II
- LeetCode Palindrome Partitioning I&&Palindrome Partitioning II
- LeetCode Palindrome Partitioning, Palindrome Partitioning II
- [Leetcode][python]Palindrome Partitioning/Palindrome Partitioning II
- Leetcode:Palindrome Partitioning & Palindrome Partitioning II
- LeetCode: Palindrome Partitioning
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode 122: Palindrome Partitioning
- leetcode:Palindrome Partitioning II
- leetcode:Palindrome Partitioning
- 【leetcode】Palindrome Partitioning
- 【leetcode】Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- Leetcode - Palindrome Partitioning
- LeetCode之Palindrome Partitioning
- [LeetCode]Palindrome Partitioning
- hdu-1429 胜利大逃亡(续)
- 小感
- jquery mobile
- source insight支持.S的汇编文件和禁止for if等下一行缩进
- C语言str系列库函数之strtok()
- [leetcode]Palindrome Partitioning
- 又要开始一次重要的选择
- jg-table 教程2 ( jgTable )
- [实验]通过内核Patch去掉iOS-v4.3.3的沙盒特性
- 使用Cglib创建动态代理
- Java 集合系列目录(Category)
- 未来属于数据科学家
- 大数据
- Java 容器之Hashset 详解.