Palindrome Partitioning I
来源:互联网 发布:circrna数据库 编辑:程序博客网 时间:2024/04/30 13: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"] ]
public class Solution { ArrayList<ArrayList<String>> res;ArrayList<String> partition;public ArrayList<ArrayList<String>> partition(String s) {// Start typing your Java solution below// DO NOT write main() functionres = new ArrayList<ArrayList<String>>();partition = new ArrayList<String>();partitioning(s);return res;}public void partitioning(String s) {int n = s.length();if (n == 0) {ArrayList<String> temp = new ArrayList<String>();for(int i = 0; i < partition.size(); i ++){temp.add(partition.get(i));}res.add(temp);return;}for (int i = 0; i < n; i++) {String begin = s.substring(0, i + 1);if (isPalindrome(begin)) {partition.add(begin);partitioning(s.substring(i + 1));partition.remove(partition.size() - 1);}}}public boolean isPalindrome(String s) {if (s.length() <= 1)return true;int begin = 0;int end = s.length() - 1;while (begin < end) {if (s.charAt(begin) == s.charAt(end)) {begin++;end--;} elsereturn false;}return true;}}
- Palindrome Partitioning I
- 【DP】Palindrome Partitioning I
- Palindrome Partitioning I && II
- [LeetCode] Palindrome Partitioning I
- Palindrome Partitioning I II
- Palindrome Partitioning I,II
- LeetCode Palindrome Partitioning I&&Palindrome Partitioning II
- Problem I : Palindrome Partitioning I
- Leetcode: Palindrome Partitioning I & II
- leetcode Palindrome Partitioning I II
- 【LeetCode】Palindrome Partitioning I&II
- 【LeetCode】Palindrome Partitioning I && II
- LeetCode - Palindrome Partitioning I && II
- LeetCode | Palindrome Partitioning I,II
- 【LeetCode】palindrome-partitioning i&ii
- [LeetCode] Palindrome Partitioning I&II
- LeetCode132 Palindrome Partitioning II&I
- leetcode之 Palindrome Partitioning I&II
- 数学常数e的含义
- linux下解压缩rar、zip文件方法
- Input/Output with files
- dicomsdl
- 用Matlab处理Dicom图像
- Palindrome Partitioning I
- Android 下通过jni读取i2c数据
- 时间字段的读取
- css中的*代表对所有控件起作用
- UVa 10069 - Distinct Subsequences
- Eclipse用法和技巧七:自动生成get和set方法2
- 客户端数据校验器
- 操作系统μC/OS-II的特点
- android 工程开发问题Failed java.util.EmptyStackException