Class Solution

java.lang.Object
g0401_0500.s0409_longest_palindrome.Solution

public class Solution extends Object
409 - Longest Palindrome.<p>Easy</p> <p>Given a string <code>s</code> which consists of lowercase or uppercase letters, return <em>the length of the <strong>longest palindrome</strong></em> that can be built with those letters.</p> <p>Letters are <strong>case sensitive</strong> , for example, <code>&quot;Aa&quot;</code> is not considered a palindrome here.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abccccdd&rdquo;</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> One longest palindrome that can be built is &ldquo;dccaccd&rdquo;, whose length is 7.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;a&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;bb&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 2000</code></li> <li><code>s</code> consists of lowercase <strong>and/or</strong> uppercase English letters only.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestPalindrome

      public int longestPalindrome(String s)