LeetCode Palindrome Partitioning
来源:互联网 发布:php函数手册 编辑:程序博客网 时间:2024/06/01 08:56
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: bool isPalindrome(const string &s, int first, int last) { if (first == last) return true; while (first < last) { if (s[first]!=s[last]) return false; first++; last--; } return true; } void _partition(const string &s, int first, vector<string> par) { if (first == s.length()) result.push_back(par); int i; for (i=first;i<s.length();i++) { if (isPalindrome(s, first, i)) { par.push_back(s.substr(first, i-first+1)); _partition(s, i+1, par); par.pop_back(); } } } vector<vector<string> > partition(string s) { result.clear(); vector<string> par; _partition(s, 0, par); return result; } vector<vector<string> > result;};
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
- win7环境搭建PHP+Apache
- Codeforces 450B Jzzhu and Sequences
- 好的排名并非更新不可
- 125_leetcode_Max Points on a Line
- Hibernate OneToOne注解配置
- LeetCode Palindrome Partitioning
- android中sqlite中判断表或视图是否存在
- JS window.open()属性
- Error_code: 1236 log event entry exceeded max_allowed_packet 错误解决办法
- Android内存分析和调优
- HDOJ 4858 项目管理
- UVaLive 4851 UVa 1468 - Restaurant (思维)
- js兼容多浏览器的关闭当前页面
- Android中的定时器AlarmManager简介