[Leetcode] 131. Palindrome Partitioning
来源:互联网 发布:软件界面设计培训 编辑:程序博客网 时间:2024/05/01 12:20
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"] ]
import java.util.ArrayList;public class Solution { public ArrayList<ArrayList<String>> partition(String s) { ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>(); if(s == null || s.length() == 0) return result; ArrayList<String> list = new ArrayList<String>(); helper(s, result, list, 0); return result; } private void helper(String s, ArrayList<ArrayList<String>> result, ArrayList<String> list, int start){ if(start == s.length()) result.add(new ArrayList<String>(list)); for(int i = start; i < s.length(); i++){ String current = s.substring(start, i + 1); if(isPalindrome(current)){ list.add(current); helper(s, result, list, i + 1); list.remove(list.size() - 1); } } } private boolean isPalindrome(String s){ int beg = 0; int end = s.length() - 1; while (beg < end) { if (s.charAt(beg) != s.charAt(end)) { return false; } beg++; end--; } return true; }}
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
- WPF Resource资源
- 算法设计方法
- 我的iphone6土豪金被偷如何使用定位找回手机?
- windows 下制造内存短缺的狠招
- Android内存分析和调优
- [Leetcode] 131. Palindrome Partitioning
- 【网络流24题】----题解(部分,持续更新...)
- Java中Set巧用,去掉重复数据
- arm9 点亮led程序优化导致全亮问题
- C++ 常变量
- 在O(1)时间删除链表结点
- 关于构造函数的调用---java
- 人性多面性的终极教材——北漂18年(4)
- C\C++几个内存处理函数