#409

Longest Palindrome

pupil · 405 · lc easy +24 · verified · 55.9% accepted · 6,352 likes · top 49%

play →

Description

Given a string s composed of lowercase and uppercase letters, determine the longest palindrome that can be constructed using any subset of those characters. Letter case matters: 'A' and 'a' are considered different characters.

Example 1:

Input: s = "abccccdd"
Output: 7
Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7.

Example 2:

Input: s = "a"
Output: 1
Explanation: The longest palindrome that can be built is "a", whose length is 1.

Code

1
2
3