leetcode Palindrome Partitioning
来源:互联网 发布:骑行软件下载 编辑:程序博客网 时间:2024/06/07 23:55
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"] ]
思路:总体想法同restoreIpAddresses相似,采用遍历整个字符串的方式。
//3333333333333333333333333333333 //判断字符串是否是回文 bool isPalindrome2(string s) { if(s.size()<=1) return true; int startIndex=0; int endIndex = s.size()-1; while(startIndex<=endIndex){ if(s[startIndex]==s[endIndex]){ startIndex++; endIndex--; continue; } return false; } return true; } vector<vector<string> > partition(string s) { vector<vector<string> > result; vector<string> partTmp; dfsPart(s,0,result,partTmp); return result; } void dfsPart(string s, int start, vector<vector<string> > &result,vector<string> partTmp){ //结束,合理的情况 if(start==s.size()){ result.push_back(partTmp); } string t; for(int i=start; i<s.size(); i++){ t += s[i]; if(isPalindrome2(t)){ partTmp.push_back(t); dfsPart(s,i+1,result,partTmp); partTmp.pop_back(); } } } //3333333333333333333333333333333333
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
- jxl操作excel进行批量导入 、导出
- MUSB架构分析(1)
- coredump设置方法
- 在Ubuntu中安装Redis
- T-SQL入门攻略之2-SQL数据类型
- leetcode Palindrome Partitioning
- java 两个文件合并程序
- HTML标签之marquee
- Python核心编程学习笔记(四)
- 教你如何制造皱纹
- 软件架构.(2)
- 使用VisualNet制作通信资光纤源管理系统效益分析
- 单向链表快速排序
- 教你几招除鞋臭