Skip to content

Instantly share code, notes, and snippets.

@piusayowale
Created September 11, 2022 20:09
Show Gist options
  • Save piusayowale/76cc72bfd3ddc6b754154160650e1268 to your computer and use it in GitHub Desktop.
Save piusayowale/76cc72bfd3ddc6b754154160650e1268 to your computer and use it in GitHub Desktop.
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