leetcode - Palindrome Partitioning
来源:互联网 发布:网易泄露数据库下载 编辑:程序博客网 时间:2024/05/13 14:33
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: std::vector<std::vector<std::string>> partition(std::string s) {std::vector<std::vector<std::string>> result;std::vector<std::string> ans;dfs(s,ans,result);#if 0for (int i = 0; i < result.size(); i++){for (int j = 0; j < result[i].size(); j++){std::cout << result[i][j] << " ";}std::cout << std::endl;}#endif // 1return result; }private:void dfs(std::string s,std::vector<std::string> &ans,std::vector<std::vector<std::string>> &result){if(s.size() < 1){result.push_back(ans);return ;}for (int i = 0; i < s.size(); i++){int a = 0,b = i;while(a < b){if(s[a] == s[b]) a++,b--;else break;}if(a >= b){ans.push_back(s.substr(0,i+1));dfs(s.substr(i+1),ans,result);ans.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
- js的dom编程中opener父窗口和子窗口(封装document.getElementById问题)
- 手把手教你: LNK2019: 无法解析的外部符号
- 扩展阅读资料
- excel使用技巧
- cookie的使用
- leetcode - Palindrome Partitioning
- 周期串问题
- PHP表单常用正则表达式(URL、HTTP、手机、邮箱等)
- C专家编程--笔记
- 用左移来实现*2^n
- 《Head First Design Patterns》读书笔记之迭代器模式
- gdb调试多进程程序
- 为VisualStudio默认模板添加版权信息
- C++primer 第四版 Page83 习题3.14