Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int longestPalindrome(string s) {
- int oddCount = 0;
- unordered_map<char, int> ump;
- for(char ch : s) {
- ump[ch]++;
- if (ump[ch] % 2 == 1)
- oddCount++;
- else
- oddCount--;
- }
- if (oddCount > 1)
- return s.length() - oddCount + 1;
- return s.length();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment