C++ solution using unordered_map 9ms


  • 0
    N

    '''
    class Solution {
    public:
    int longestPalindrome(string s) {
    int res=0;
    if(s.size()==0) return 0;
    unordered_map<char,int> mymap;
    for(auto ch:s)
    mymap[ch]++;
    int single=0;
    for(auto it:mymap){
    if(it.second&1==1){
    res--;
    single=1;
    }
    res+=it.second;
    }
    return res+single;
    }
    };
    '''


  • 0
    N
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.