leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0409.cpp (347B)
0 class Solution {
1 public:
2 int longestPalindrome(string s) {
3 unordered_map<char, int> um;
4 for (char c : s)
5 um[c]++;
7 int res = 0;
8 bool odd = false;
9 for (auto [c, v] : um) {
10 if (v % 2 && !odd) odd = true;
11 res += v / 2;
12 }
13 return res * 2 + odd;
14 }
15 };