131-Palindrome Partitioning
来源:互联网 发布:java axis2 调用wsdl 编辑:程序博客网 时间:2024/06/05 17:11
题目
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”]
]
分析
实现
/*Author: FancyDate:2017-03-21Algorithm:131-Palindrome PartitioningTime Compeliexity:*/class Solution {public: vector<vector<string>> partition(string s) { vector<vector<string>> res; vector<string> curr; if (s.empty()) return res; dfs(res, curr, s, 0); return res; } //深度遍历 void dfs(vector<vector<string>> &res, vector<string>& curr, string& s, int index) { //index == s.size时代表已经处理完该字符串 if (index == s.size()) { res.push_back(curr); return; } for (int i = index; i < s.size();i++) //判断是否回文,如果是,则push,并递归处理剩余的字串 if (isPalindrome(s, index, i)) { curr.push_back(s.substr(index, i - index + 1)); dfs(res, curr, s, i + 1); //BackTracking curr.pop_back(); } } //判断字符串是否回文 bool isPalindrome(string s, int start, int end) { if (start == end) return true; while (start < end ) { if (s[start] != s[end]) return false; start++; end--; } return true; }};
阅读全文
0 0
- LeetCode: Palindrome Partitioning [131]
- 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
- 131 Palindrome Partitioning
- 131 Palindrome Partitioning [Leetcode]
- LeetCode 131 Palindrome Partitioning
- 131Palindrome Partitioning
- Leetcode 131:Palindrome Partitioning
- 【LeetCode-131】Palindrome Partitioning
- Leetcode 131 Palindrome Partitioning
- [leetCode 131]Palindrome Partitioning
- 121-Best Time to Buy and Sell Stock
- 94. Binary Tree Inorder Traversal 中序遍历
- Java
- 123-Best Time to Buy and Sell Stock III
- Maven:Failed to create a Maven project ‘…pom.xml’ already exists in VFS 解决
- 131-Palindrome Partitioning
- swift-判断是否已获得相机、相册权限
- 132-Palindrome Partitioning II
- 模型汇总17 基于Depthwise Separable Convolutions的Seq2Seq模型_SliceNet原理解析
- Windows下Anaconda2(Python2)和Anaconda3(Python3)的共存,Beautiful Soup模块的安装
- 141-Linked List Cycle
- JavaMail第三方库-sendCloud
- 【Jetson Tx2 视觉slam开发】入门配置
- 217-Contains Duplicate