[LeetCode] 131. Palindrome Partitioning
来源:互联网 发布:泰国人用淘宝吗 编辑:程序博客网 时间:2024/06/07 01:01
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> comb; partition(res, comb, s, 0); return res; }private: void partition(vector<vector<string>>& res, vector<string>& comb, string& s, int base) { if (base == s.length()) { res.push_back(comb); return; } for (int i = base; i < s.length(); i++) { if (IsPalindrome(s, base, i)) { comb.push_back(s.substr(base, i - base + 1)); partition(res, comb, s, i + 1); comb.pop_back(); } } } bool IsPalindrome(string& s, int i, int j) { for (; i <= j && s[i] == s[j]; i++, j--) ; return i > j; }};
阅读全文
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
- 关于easyUI一些标签的使用
- 组合数取模,预处理阶乘逆元模板
- android 如何通过拨号盘暗码启动你的应用
- MFC颜色对话框的使用
- 欢迎使用CSDN-markdown编辑器
- [LeetCode] 131. Palindrome Partitioning
- HDU 6033 Add More Zero
- 百练_4106:出现两次的字符-Characters Appearing twice
- Mybatis
- 关于android自定义View时使用paint.setXfermode注意
- 数据结构与算法专题之线性表——链表(一)单链表
- MFC中获取HDC
- getContextPath、getServletPath、getRequestURI的区别
- Java虚拟机详解----JVM内存结构