All Possible Unique combination of Palindrome substring from a Given String
SOURCE : DifferentCominationOfPERMUTAION.javaimport java.util.HashSet;public class DifferentCominationOfPERMUTAION { public static void main(String[] args) { String str = "aaabbbcccdddjdjzscijsghfy"; HashSet hs = new HashSet<>(); for (int i = 0; i < str.length(); i++) { for (int j = i + 1; j <= str.length(); j++) { if (isplaind(str.substring(i, j))) hs.add(str.substring(i, j)); } } System.out.println(hs); } private static boolean isplaind(String str) { if (str.length() > 0) { for (int i = 0, j = str.length() - 1; i <= j; i++, j--) { if (str.charAt(i) == str.charAt(j)) { continue; } else return false; } return true; } return false; }} INPUTString str = "aaabbbcccdddjdjzscijsghfy";OUTPUT
[aa, aaa, bb, cc, dd, a, b, ccc, bbb, c, d, ddd, f, g, h, i, j, jdj, s, y, z, djd]

0 comments :
Post a Comment