Palindrome Partitioning
来源:互联网 发布:大专php电商网站教程 编辑:程序博客网 时间:2024/04/29 23: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"] ]
public class Solution { public List<List<String>> partition(String s) { List<List<String>> result = new ArrayList<List<String>>(); List<String> path = new ArrayList<String>(); if(s == null || s.length() == 0){ return result; } helper(s,result,path,0); return result; } private boolean isPalindrome(String s){ int start = 0; int end = s.length() - 1; while(start < end){ if(s.charAt(start) != s.charAt(end)) return false; start++; end--; } return true; } private void helper(String s,List<List<String>> result,List<String> path, int position){ if(position == s.length()){ result.add(new ArrayList<String>(path)); } for(int i = position+1; i <= s.length(); i++){ String prefix = s.substring(position,i); if(!isPalindrome(prefix)){ continue; } path.add(prefix); helper(s,result,path,i); path.remove(path.size()-1); } }}
0 0
- 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
- Android中的Intent详细讲解
- Linux系统IPC进程间通信
- mybatis查询缓存
- Android进程间通信(IPC)之实现细节篇(一) Binder驱动
- HDU 1049.Climbing Worm【水!水!水!】【8月25】
- Palindrome Partitioning
- android中activity详解
- UIday01: UIView及其子类 UIView UILabel frame center bounds 管理视图层次 控制文本显示
- UITabBarController (loading...)
- 最快的计算2的N次方
- 事件机制实现超时触发功能,同时捕捉Ctrl+C信号
- 欢迎使用CSDN-markdown编辑器
- VC++和Matlab混合编程(在VC中调用将.m文件生成的DLL)
- Matlab实现Galton板的动画演示