[leetcode]131. Palindrome Partitioning
来源:互联网 发布:淘宝只退款不退货教程 编辑:程序博客网 时间:2024/06/03 22:55
题目链接:https://leetcode.com/problems/palindrome-partitioning/#/description
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>> res; vector<string> tmp; getPartition(s,0,tmp,res); return res; }private: void getPartition(string& s,int idx,vector<string>& tmp,vector<vector<string>>& res) { if(idx==s.length()) { res.push_back(tmp); return; } for(int i=idx,n=s.length();i<n;i++) { int l=idx,r=i; while(l<r && s[l]==s[r]) { l++; r--; } if(l>=r) { tmp.push_back(s.substr(idx,i-idx+1)); getPartition(s,i+1,tmp,res); tmp.pop_back(); } } }};
阅读全文
0 0
- LeetCode 131. Palindrome Partitioning
- [LeetCode]131.Palindrome Partitioning
- [Leetcode] 131. Palindrome Partitioning
- [leetcode] 131.Palindrome Partitioning
- [LeetCode]131. Palindrome Partitioning
- 131. Palindrome Partitioning LeetCode
- Leetcode 131. Palindrome Partitioning
- LeetCode 131. Palindrome Partitioning
- LeetCode *** 131. Palindrome Partitioning
- LeetCode 131. Palindrome Partitioning
- LeetCode-131.Palindrome Partitioning
- 【leetcode】131. Palindrome Partitioning
- [leetcode] 131. Palindrome Partitioning
- 【Leetcode】131. Palindrome Partitioning
- [LeetCode] 131. Palindrome Partitioning
- Leetcode-131. Palindrome Partitioning
- 【LeetCode】131. Palindrome Partitioning
- Leetcode 131. Palindrome Partitioning
- 双链表的操作
- [iOS @2x @3x pt px 分辨率]
- 想要给PDF文件添加标签该如何去进行操作
- 排序算法之堆排序
- Web.xml配置详解之context-param
- [leetcode]131. Palindrome Partitioning
- ThreadLocal与ThreadLocalMap源码解析
- Spark成长之路(8)-TFIDF
- 剑指offer面试题[54]-表示数值的字符串
- fatcache源码阅读记录
- 【Redis基础】发布与订阅
- Android_Action和Category属性
- android,actionbar,menu显示,图片,菜单禁用★★★
- 草稿