Leetcode Palindrome Partitioning
来源:互联网 发布:wow数据库 3.35 编辑:程序博客网 时间:2024/06/08 02:25
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> tmp; part(s,0,tmp,result); return result; } bool check(string s,int start,int end) { while(start<end) { if(s[start] != s[end]) return false; start++;end--; } return true; } void part(string s,int start,vector<string>& tmp,vector<vector<string>>& result) { if(start == s.size()) { result.push_back(tmp); return; } for(int i=start;i<s.size();i++) { if(check(s,start,i)) { tmp.push_back(s.substr(start,i-start+1)); part(s,i+1,tmp,result); tmp.pop_back(); } } } };
阅读全文
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
- C#的控件伸缩实现
- ios学习
- ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解决
- 【小白成长史】在onlick事件中跳转的失效
- 微信小程序--data的赋值与取值
- Leetcode Palindrome Partitioning
- 网络判断
- shell 数组遍历的3种方法
- C++数组以及指针学习的技巧
- mysql查看正在运行的语句
- Kotlin(一)
- Lucene从入门到进阶(6.6.0版本)
- repo/git 常见问题纪录
- Struts2的国际化和消息处理