# 409. Longest Palindrome [source](https://leetcode.com/problems/longest-palindrome/description/) > Date: 12/29 > Array ### Mimi's solution time complexity: $O(n)$ ```cpp class Solution { public: int longestPalindrome(string s) { unordered_map<char, int> m; for (char c: s) if (m.find(c) == m.end()) m[c] = 1; else m[c] += 1; int sum = 0; for (auto it: m) { sum += it.second / 2 * 2; if (sum % 2 == 0 && it.second % 2 == 1) sum += 1; } return sum; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up