leetcode 409. Longest Palindrome
int longestPalindrome(string s) { unordered_map<char, int> m; for (char i : s) m[i]++; bool flag = false; int ret = 0; for (auto i : m) { auto res = i.second; if (res % 2 == 1) { ret = ret + res - 1; flag = true; } else ret = ret + res; } return flag ? ret + 1 : ret; }
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】