Longest Chunked Palindrome Decomposition LeetCode solution in Java

1
class Solution {
2

3
public int longestDecomposition(String text) {
4
int n = text.length();
5
for (int i = 0; i < n / 2; i++)
6
if (text.substring(0, i + 1).equals(text.substring(n - 1 - i, n)))
7
return 2 + longestDecomposition(text.substring(i + 1, n - 1 - i));
8
return (n == 0) ? 0 : 1;
9
}
10
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0