Given a string s, partition s such that every substring of the partition is a palindrome.

Return all possible palindrome partitioning of s.

Example:

Input: "aab"
Output:
[
["aa","b"],
["a","a","b"]
]
class Solution {
public List<List<String>> partition(String s) {
List<List<String>> res = new ArrayList<>();
List<String> list = new ArrayList<>();
helper(res, list, 0, s);
return res;
} private void helper(List<List<String>> res, List<String> list, int level, String s) {
if (level == s.length()) {
res.add(new ArrayList<>(list));
return;
}
for (int i = level; i < s.length(); i++) {
if (isPalin(s, level, i)) {
list.add(s.substring(level, i + 1));
helper(res, list, i + 1, s);
list.remove(list.size() - 1);
}
}
} private boolean isPalin(String s, int start, int end) {
while (start < end) {
if (s.charAt(start) != s.charAt(end)) {
return false;
}
start += 1;
end -= 1;
}
return true;
} }

[LC] 131. Palindrome Partitioning的更多相关文章

  1. leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II

    131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...

  2. Leetcode 22. Generate Parentheses Restore IP Addresses (*) 131. Palindrome Partitioning

    backtracking and invariant during generating the parathese righjt > left  (open bracket and cloas ...

  3. Leetcode 131. Palindrome Partitioning

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  4. 131. Palindrome Partitioning

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  5. 78. Subsets(M) & 90. Subsets II(M) & 131. Palindrome Partitioning

    78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: The solution ...

  6. [leetcode]131. Palindrome Partitioning字符串分割成回文子串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  7. 【LeetCode】131. Palindrome Partitioning

    Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...

  8. 131. Palindrome Partitioning (Back-Track, DP)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  9. 131. Palindrome Partitioning(回文子串划分 深度优先)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

随机推荐

  1. POJ 2676:Sudoku 数独

    Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15830   Accepted: 7737   Special ...

  2. tfield的字段名和显示名

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  3. Mycat简介及适用场景

    官网:http://www.mycat.io/ 一.Mycat是什么 Mycat是一个开源的分布式数据库系统,是一个实现了 MySQL 协议的的 Server,前端用户可以把它看作是一个数据库代理,用 ...

  4. 吴裕雄--天生自然MySQL学习笔记:MySQL 正则表达式

    下表中的正则模式可应用于 REGEXP 操作符中. 实例 查找name字段中以'st'为开头的所有数据: mysql> SELECT name FROM person_tbl WHERE nam ...

  5. 主席树--动态区间第k小

    主席树--动态区间第\(k\)小 模板题在这里洛谷2617. 先对几个问题做一个总结: 阅读本文需要有主席树的基础,也就是通过区间kth的模板题. 静态整体kth: sort一下找第k小,时间复杂度\ ...

  6. python刷LeetCode:3.无重复字符的最长子串

    难度等级:中等 题目描述: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 ...

  7. JavaScript学习总结(五)

    之前的几讲中我们曾经说过,JavaScript中是没有类的概念的.但是我们讲过对象,那么这个对象是怎么来的呢? 只要有函数即可创建对象 自定义对象 自定义对象的方式: 1. 使用无参的函数创建对象 & ...

  8. Dp(NOIp级)全解

    2018年(你还真以为我会讲保卫王国2333 LuoguP5020 货币系统 这道题就相当于求{A}的线性基大小 证明: 反证法,设该解为B,那么B定能表示出{A}的线性基,即{A}的线性基中所有数都 ...

  9. 数据处理pandas

    1.缺失值时间戳不为NaN,为NaT, 同样判断都为isna()或notna()方法2.删值\去重 df.dropna() df.drop_duplicates() 3.上下值插值 df.fillna ...

  10. nginx_tcp_proxy代理酸酸乳

    一.安装低版本的nginx(高版本不支持tcp代理模块:nginx_tcp_proxy_module)Nginx默认只支持http反向代理,要支持tcp反向代理,需在编译时增加tcp代理模块[ngin ...