leetCode题解之Longest Palindrome

时间:2021-11-10 23:50:19

1、题目描述

leetCode题解之Longest Palindrome

2、问题分析

直接用hash table 做就行。

3、代码

 int longestPalindrome(string s) {
if(s.size() == )
return ;
map<char,int> m;
for(auto &c : s)
m[c]++; int ans = ;
int odd = ;
for(auto p = m.begin(); p != m.end() ; ++p ){
if( p->second % == )
ans += p->second;
else{
ans += p->second-;
odd++;
} }
if (odd != )
ans += ;
return ans; }