131. Palindrome Partitioning
来源:互联网 发布:linux snmp v3 配置 编辑:程序博客网 时间:2024/06/10 16:04
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"] ]题意:返回string s的各种回文段划分。
思路:回溯。
class Solution {public:vector<vector<string>> partition(string s) {vector<string> cur;vector<vector<string>> res;backtracking(cur, 0, 0, s, res);return res;}private:void backtracking(vector<string>& cur, int len, int begin, string& s, vector<vector<string>>& res){if (len == s.size()){res.push_back(cur);return;}for (int i = 0; i+begin < s.size(); i++){string tmp = s.substr(begin, i+1);if (isPalindrome(tmp)){cur.push_back(tmp);backtracking(cur, len + tmp.size(), begin + i + 1, s, res);cur.pop_back();}}}bool isPalindrome(string s){int i = 0;int j = s.size() - 1;while (i < j){if (s[i] != s[j]){return false;}i++;j--;}return true;}};
0 0
- 131. Palindrome Partitioning && 132. Palindrome Partitioning II
- LeetCode 131. Palindrome Partitioning
- [LeetCode]131.Palindrome Partitioning
- [Leetcode] 131. Palindrome Partitioning
- [leetcode] 131.Palindrome Partitioning
- 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- [LeetCode]131. Palindrome Partitioning
- 131. Palindrome Partitioning LeetCode
- 131. Palindrome Partitioning
- Leetcode 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- LeetCode 131. Palindrome Partitioning
- LeetCode *** 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- LeetCode 131. Palindrome Partitioning
- iOS 应用将适应新的的IPv6-only网络 -解决方案
- 『Python学习』lettcode题目答案python版
- fastcgi与php-fpm之间关系
- jquery checkbox 操作
- Object-C之动态类型(isKindOfClass, isMemberOfClass,id)等
- 131. Palindrome Partitioning
- 网易视频云技术分享:Facebook memcache优化经验
- jquery+ajax实现多个下拉选之间的关联
- myEclipse中debug模式项目启动慢没响应
- 友谊的小船永远都不会翻【张悦生日快乐】
- Hibernate Hql详解
- 最快速度找到内存泄漏
- Unity3D中的线性插值Lerp()函数解析
- hadoop2.6解决 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... 问题