Clean C++ Solution


  • 0
    I
    int longestPalindrome(string s)
    {
    	unordered_map<char, int> letters;
    
    	auto evenCount = 0;
    
    	for (auto chr : s)
    	{
    		letters[chr]++;
    		if (letters[chr] == 2)
    		{
    			evenCount += 2;
    			letters[chr] = 0;
    		}
    	}
    
    	return (s.size() > evenCount) ? evenCount + 1 : evenCount;
    }
    

Log in to reply
 

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