C++ solution using bitset


  • 0
    H
    class Solution {
    public:
        int longestPalindrome(string s) {
            bitset<52> set;
            for (char c : s) {
                int i = (c > 'Z') ? (c - 'a' + 26) : (c - 'A');
                set.flip(i);
            }
    
            int odd = set.count();
            return s.size() - (odd == 0 ? 0 : odd - 1);
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.