Created
September 11, 2022 20:09
-
-
Save piusayowale/76cc72bfd3ddc6b754154160650e1268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int longestPalindrome(string s) { | |
map<char, int> count; | |
for (char c: s){ | |
count[c]++; | |
} | |
int ans = 0; | |
for (auto v: count) { | |
ans += v.second / 2 * 2; | |
if (ans % 2 == 0 && v.second % 2 == 1) | |
ans++; | |
} | |
return ans; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment