Data Structure & Algorithm: Level-1 Problem #28. Longest Palindrome

Given a string with lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Note that letters are case sensitive, for example, “aA” is not considered a palindrome here.

Sample Input:

“aabbBccccddd”

Sample Output:

11

Given the above sample string, the longest palindrome we can create is “abccdddccba”, and the length is 11.

数据结构和算法:初级练习题 #28 – 最长回文

回文是正反读都一样的词语。给定一个包含大小写字母的字符串,计算用该字符串里的字母来重新排列,可以组成最长回文的字数。

输入样例:

“aabbBccccddd”

输出样例:

11

用上面字符串里的字母来排列,最长回文是: “abccdddccba”,其长度是 11。

Python Solutions

Longest Palindrome