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. IDEA控制台输出中文乱码日志文件正常

    控制台中文输出乱码但输出的日志文件正常 idea.exe.vmoptions与idea64.exe.vmoptions已经配置 -Dfile.encoding=UTF-8 logback.xml中也配 ...

  2. axios请求接口的时候带一个参数

    getHomeInfo () { this.axios.get('/api/index.json?city=' + this.city) .then(this.getHomeInfoSucc) } 尽 ...

  3. convolution in frequency domain

    https://blog.csdn.net/myjiayan/article/details/72427995 convolution in frequency domain convolution ...

  4. 7)给tab下面添加一个子非模态对话框

    1)还是沿袭(6)那个代码 2)下面是步骤: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·~~~~~~~~~~~~~~~~~~~~~~~~~~~ 然后,修改这个对 ...

  5. alert(1&&2)的输出问题

    此文章转载自http://blog.csdn.net/xiaotao_css/article/details/61940664 一.先来说说 ||(逻辑或),从字面上来说,只有前后都是false的时候 ...

  6. Java 面向对象概述原理: 多态、Object类,转型(8)

    Java 面向对象概述原理: 多态.Object类,转型(8) http://docs.oracle.com/javase/tutorial/java/IandI/override.html Java ...

  7. 2019牛客暑期多校训练营(第七场)A.String【最小表示法】

    传送门:https://ac.nowcoder.com/acm/contest/887/A 题意:大意就是给你一个只含有0和1的字符串,找出一种分割方法,使得每个分割出的字符串都是在该字符串自循环节中 ...

  8. Ubuntu的奇技淫巧

    sudo apt-get install cmatrix 输入密码,安装后,按F11把terminal全屏,输入cmatrix -b sudo apt-get install sl 安装后执行sl,屏 ...

  9. Linux上创建RStudio快捷方式

    在Linux平台上经常会有一些软件需要通过命令行的方式启动,这没有图标启动方便,下面是在Linux平台为RStudio创建图标链接的方法: 下面以在桌面上创建RStudio快捷方式为例: (1) 首先 ...

  10. 基础练习--huffman

    问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, pn-},用这列数构造Huffman树的过程如下: . 找 ...