[Leetcode] Palindrome Partitioning
来源:互联网 发布:三星s4可以用4g网络吗 编辑:程序博客网 时间:2024/04/30 08:18
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<String> cur = new ArrayList<>(); List<List<String>> result = new ArrayList<>(); partition(s.toCharArray(), 0, cur, result); return result; } private void partition(char[] s, int start, List<String> cur, List<List<String>> result) { if(start == s.length) { result.add(new ArrayList<>(cur)); return; } StringBuilder str = new StringBuilder(); for(int i = start; i < s.length; i++) { str.append(s[i]); if(isPalindrome(str)){ cur.add(str.toString()); partition(s, i+1, cur, result); cur.remove(cur.size() - 1); } } return; } private boolean isPalindrome(StringBuilder str) { int start = 0; int end = str.length() - 1; while(start <= end) { if(str.charAt(start) != str.charAt(end)) { return false; } start++; end--; } return true; }}
0 0
- 【leetcode】Palindrome Partitioning && Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning && Palindrome Partitioning II
- LeetCode Palindrome Partitioning I&&Palindrome Partitioning II
- LeetCode Palindrome Partitioning, Palindrome Partitioning II
- [Leetcode][python]Palindrome Partitioning/Palindrome Partitioning II
- Leetcode:Palindrome Partitioning & Palindrome Partitioning II
- LeetCode: Palindrome Partitioning
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode 122: Palindrome Partitioning
- leetcode:Palindrome Partitioning II
- leetcode:Palindrome Partitioning
- 【leetcode】Palindrome Partitioning
- 【leetcode】Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- Leetcode - Palindrome Partitioning
- LeetCode之Palindrome Partitioning
- [LeetCode]Palindrome Partitioning
- Scala Cookbook读书笔记 Chapter 4.Classes and Properties 第一部分
- MITA和MAUI框架
- phpstorm安装
- Qt之QTcpServer/QTcpSocket简单收发信息(1)
- js实现网页全屏切换(平滑过渡),鼠标滚动切换
- [Leetcode] Palindrome Partitioning
- 【php】数组 取某一列的值 array_column
- Spark与Mysql的交互
- Qt程序如何在Mac上用X-code编译
- SetWindowsHookEx 详解(四)所有结构体
- LeetCode 338.Counting Bits 题解(C++)
- linux安装MySql问题汇总
- 【5】SimpleTrigger
- Qt网络应用----socket通信例子