亚麻:Longest Palindrome
亚麻 的OA题
代码在leetcode 测试通过; leetcode 链接
https://leetcode.com/problems/longest-palindrome/description/
class Solution { public: int longestPalindrome(string s) { if( s.empty () ) return 0; unordered_map< char, int > res; int max =0; bool oflag = false; for (auto& e: s) res[e]+=1; for (auto& e: res){ if (e.second%2 == 0) max += e.second; else { oflag = true ; max += e.second -1; } } if(oflag) return max +1; else return max; } };