@@ -0,0 +1,1564 @@
+package problems;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class PalindromePartitioning %7B%0A    public List%3CList%3CString%3E%3E partition(String s) %7B%0A        final int n = s.length();%0A        if (n == 0)%0A            return new ArrayList%3CList%3CString%3E%3E();%0A%0A        boolean%5B%5D%5B%5D b = new boolean%5Bn%5D%5Bn%5D;%0A        for (int i = 0; i %3C n - 1; i++) %7B%0A            b%5Bi%5D%5Bi%5D = true;%0A            b%5Bi%5D%5Bi + 1%5D = s.charAt(i) == s.charAt(i + 1);%0A        %7D%0A        b%5Bn - 1%5D%5Bn - 1%5D = true;%0A%0A        for (int i = 3; i %3C= n; i++) %7B%0A            for (int x = 0; x %3C n + 1 - i; x++) %7B%0A                if (s.charAt(x) == s.charAt(x + i - 1))%0A                    b%5Bx%5D%5Bx + i - 1%5D = b%5Bx + 1%5D%5Bx + i - 2%5D;%0A            %7D%0A        %7D%0A%0A        return trace(b, s, 0);%0A    %7D%0A%0A    List%3CList%3CString%3E%3E trace(boolean%5B%5D%5B%5D b, String s, int l) %7B%0A        int n = s.length();%0A        List%3CList%3CString%3E%3E out = new ArrayList%3CList%3CString%3E%3E();%0A%0A        if (b%5Bl%5D%5Bn - 1%5D) %7B%0A            List%3CString%3E a = new ArrayList%3CString%3E();%0A            a.add(s.substring(l));%0A            out.add(a);%0A        %7D%0A%0A        for (int i = l; i %3C n - 1; i++) %7B%0A            if (b%5Bl%5D%5Bi%5D) %7B%0A                List%3CList%3CString%3E%3E t = trace(b, s, i + 1);%0A                for (int j = 0; j %3C t.size(); j++)%0A                    t.get(j).add(0, s.substring(l, i + 1));%0A                out.addAll(t);%0A            %7D%0A        %7D%0A        return out;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        PalindromePartitioning pp = new PalindromePartitioning();%0A%0A        String s = %22a%22;%0A        System.out.println(pp.partition(s));%0A    %7D%0A%7D%0A

Add Palindrome Partitioning