Leetcode 409 Longest Palindrome

来源:互联网 发布:阿里云跟阿里巴巴关系 编辑:程序博客网 时间:2024/05/21 09:19

Leetcode 409 Longest Palindrome

class Solution {public:    int longestPalindrome(string s) {        unordered_map<char,int> charCount;        for(char ch : s)            charCount[ch] ++;        int odd = 0;        int length = 0;        for(auto ch : charCount)        {            if(ch.second & 1)                odd = 1;            length += ch.second & 0xfffffffe;//取双数,5变成4这种        }        return length + odd;    }};
原创粉丝点击