Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 661 Bytes

Longest Palindrome.md

File metadata and controls

35 lines (24 loc) · 661 Bytes
int longestPalindrome(string s) {
        
        unordered_map<char,int> m;

        for(int i=0;i<s.size();i++)
        {
            m[s[i]]++;
        }

        int ans=0;
        bool hasOddFreq= false;

        for(auto i : m)
        {
            if(i.second % 2 ==0)
                ans += i.second;

            else{
                ans +=i.second -1;
                hasOddFreq = true;
            }
                
        }

        if(hasOddFreq)
            ans +=1;

        return ans;
    }

    ```