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. MongoDB四-操作索引

    转自: http://www.cnblogs.com/huangxincheng/archive/2012/02/29/2372699.html 我们首先插入10w数据,上图说话: 一:性能分析函数( ...

  2. Windows桌面图标不见了,可能是结束了explorer.exe进程导致

    Windows桌面图标不见了,怎么办?那么可能是你关掉了explorer.exe的进程. 解决办法: ① Ctrl+shift+delete打开任务管理器,查看进程是否有explorer.exe ② ...

  3. vue中的axios请求

    1.get请求 // get this.$axios.get('请求路径') .then(function (response) { console.log(response); // 成功 }) . ...

  4. 从结构和数字看OO——面向对象设计与构造第一章总结

    不知不觉中,我已经接触OO五周了,顺利地完成了第一章节的学习,回顾三次编程作业,惊喜于自身在设计思路和编程习惯已有了一定的改变,下面我将从度量分析.自身Bug.互测和设计模式四个方向对自己第一章的学习 ...

  5. winform操作windows系统计算器

    winform对系统计算器的调用,启动,最大化最小化显示,在mainwindow设置topmost=true时,正常显示计算器并置顶. /// <summary> /// 获取窗体的句柄函 ...

  6. Unity获取游戏对象详解

    我觉得Unity里面的Transform 和 GameObject就像两个双胞胎兄弟一样,这俩哥们很要好,我能直接找到你,你也能直接找到我.我看很多人喜欢在类里面去保存GameObject对象.解决G ...

  7. selenium登陆qq邮箱页面

    from selenium import webdriver driver = webdriver.Chrome() driver.get('https://mail.qq.com/cgi-bin/l ...

  8. 题解【[BJOI2012]算不出的等式】

    题目背景emmm \[\text{首先特判掉p=q时的情况(ans = }p^2-1\text{)}\] \[\text{构造函数}f(k) = \left\lfloor \frac{kq}{p}\r ...

  9. Java 静态static关键字,main函数,对象的初始化过程,对象调用成员,单例模式的设计,静态代码块(6)

    Java 静态static关键字,静态代码块详情参考:static的使用原理讲解http://www.cnblogs.com/itcqx/p/5519464.html main函数: java Mai ...

  10. Azure App Service-添加自定义域名和SSL保护

    语雀知识库:https://www.yuque.com/seanyu/azure/appservicessl 公众号:云计算实战 案例  添加自定义域并开启SSL保护 进入App Service控制台 ...