Leetcode164: Palindrome Partitioning
来源:互联网 发布:java double e 表示 编辑:程序博客网 时间:2024/04/29 03:34
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: void dfs(string s, vector<string> &path, vector<vector<string>> &res) { if(s.size() < 1) { res.push_back(path); return; } for(int i = 0; i < s.size(); i++) { int begin = 0; int end = i; while(begin < end) { if(s[begin] == s[end]) { begin++; end--; } else break; } if(begin >= end)//bool isPalindrome = true; { path.push_back(s.substr(0,i+1)); dfs(s.substr(i+1),path,res); path.pop_back(); } } } vector<vector<string>> partition(string s) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. vector<vector<string>> res; vector<string> path; dfs(s,path,res); return res; } };
0 0
- Leetcode164: Palindrome Partitioning
- Palindrome partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- Palindrome Partitioning
- 项目管理和缺陷跟踪工具-Redmine安装部署(一)
- hdoj 母牛的故事
- php获取图片尺寸及格式
- 进度条与线程
- Elasticsearch的备份和恢复
- Leetcode164: Palindrome Partitioning
- unity编辑器学习
- Java九种基本数据类型的大小,以及他们的封装类。
- HDU 1708 Fibonacci String(字符串模拟)
- C语言设置剪辑版文本
- “南大软院大神养成计划“_第六天的学习“
- CocoaPods安装和使用教程
- 几个要闭着眼睛打出来的模版。
- Rated R: Recommended Reading