Problem Statement
A palindrome is a string that reads the same forwards and backwards. For instance, ABBA is a palindrom, but ABCBB is not. You are given a String s. Return the length of the longest substring of s that is a palindrome.
Definition
- Class:
- LongestPalindrome
- Method:
- longestLength
- Parameters:
- String
- Returns:
- int
- Method signature:
- int longestLength(String s)
- (be sure your method is public)
Notes
- A substring is a set of contiguous characters that form part of the string. For example, BCD is a substring of ABCDE, but BD is not, since B and D are not contiguous in ABCDE.
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character of s will be between 'A' and 'Z', inclusive.
Examples
"ABAA"
Returns: 3
"ABA" is a palindrome."ABB"
Returns: 2
The best we can do is "BB"."ABCBCA"
Returns: 3
"BCB" or "CBC" works, either is the same length.