mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			20 lines
		
	
	
		
			495 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
		
			495 B
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <string>
 | 
						|
#include <unordered_map>
 | 
						|
using namespace std;
 | 
						|
 | 
						|
class Solution {
 | 
						|
    public:
 | 
						|
        int longestPalindrome(string s) {
 | 
						|
            unordered_map<char, int> count;
 | 
						|
            int ans = 0;
 | 
						|
            for (char c : s)
 | 
						|
                ++count[c];
 | 
						|
            for (auto p : count) {
 | 
						|
                int v = p.second;
 | 
						|
                ans += v / 2 * 2;
 | 
						|
                if (v % 2 == 1 and ans % 2 == 0)
 | 
						|
                    ++ans;
 | 
						|
            }
 | 
						|
            return ans;
 | 
						|
        }
 | 
						|
    }; |