409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
This is case sensitive, for example "Aa"
is not considered a palindrome here.
Note: Assume the length of given string will not exceed 1,010.
Example:
解题要点:
记录每个字符出现的频率,再遍历这个数组,把字符出现的频率次数加进最终返回值,如果是偶数,则可以直接回文;如果是奇数,-1以构成回文。最后如整串只要有出现奇数数字,则单独+1到返回值里。
Last updated
Was this helpful?