get all Palindromes of a string
2016-07-30 19:20
323 查看
public static void main(String[] args) { AllPalindromes a = new AllPalindromes(); for (String str: a.getAllPalindrome("accbrrbccai2")){ System.out.println(str); }; System.out.println(); System.out.println(a.longestPalindrome("accbrrbccai2")); } List<String> res = null; public List<String> getAllPalindrome(String str) { res = new LinkedList<>(); if (str == null || str.length() <= 1) { return res; } for (int i = 0; i < str.length() * 2 - 1; i++) { int left = i/2; int right = (i)/2; if (i%2 == 1) { right++; } getPalindrome(str, left, right); } return res; } private void getPalindrome(String str, int left, int right){ while (left >= 0 && right < str.length() && str.charAt(left) == str.charAt(right)) { left--; right++; if (right - left > 2) { res.add(str.substring(left + 1, right)); } } }
相关文章推荐
- [CC150] Get all permutations of a string
- .net 中的bug:System.OutOfMemoryException At System.String.GetStringForStringBuilder
- 【leetcode】String——Substring with Concatenation of All Words(30)
- How can i get hold of all of the visible items in my QListView?
- find all the permutation of a string
- Quick props to all of the authors/sites that helped me get started with Alchemy:
- Get the rows count of all the table in Sybase
- get all rows count of all tables in a mysql database.
- Get size of all tables in database
- magento How to get all associated children product of a configurable product
- How To get the Real length of a string with chinese words
- Q9.5 Write a method to compute all permutations of a string
- Problems with System.OutOfMemoryException At System.String.GetStringForStringBuilder in 32-Bit Managed Solutions
- get content of all input tag
- 译 -- Java 并发编程(多线程)二 | Producer-Consumer | Get status of all threads | deadlocked
- 30. Substring with Concatenation of All Words (String, Map)
- String——substring-with-concatenation-of-all-words(模式匹配变型)
- Write a method to compute all permutations of a string
- print all Permutation of a string
- Get a list of all application currently installed on a phone