LEETCODE Palindrome partitioning
来源:互联网 发布:在vb集成环境中要添加 编辑:程序博客网 时间:2024/05/16 23:45
dfs回溯
public ArrayList<ArrayList<String>> partition(String s) { ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>(); if(s == null || s.length() == 0) return result; ArrayList<String> tmpRes = new ArrayList<String>(); helper(s, result, tmpRes); return result; } public void helper(String s, ArrayList<ArrayList<String>> result, ArrayList<String> tmpRes){ if(s.length() == 0){ result.add(new ArrayList<String>(tmpRes)); return; } for(int i = 0; i < s.length(); i++){ String pre = s.substring(0, i + 1); if(isPalindrome(pre)){ tmpRes.add(pre); helper(s.substring(i + 1), result, tmpRes); tmpRes.remove(tmpRes.size() - 1); } } } public 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; }
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
- qsort快速排序
- Merge Sorted Array
- H a r d F a u l t
- 好文章收藏
- 设计模式——简单工厂模式
- LEETCODE Palindrome partitioning
- 实现统计某个月内每天新增用户数的方法
- UITableView进行讲解
- 负债业务
- Android五种数据传递方法汇总
- 【ThinkingInC++】32、一个句柄类
- listview刷新数据异常
- anroid五种数据传递方式
- Vertica7 Native Connection Load Balance