Longest Chunked Palindrome Decomposition LeetCode solution in Java
1class Solution {23public int longestDecomposition(String text) {4int n = text.length();5for (int i = 0; i < n / 2; i++)6if (text.substring(0, i + 1).equals(text.substring(n - 1 - i, n)))7return 2 + longestDecomposition(text.substring(i + 1, n - 1 - i));8return (n == 0) ? 0 : 1;9}10}