4 lines C++ bit manipulation solution (works for only letters though)

  • 1
    bool canPermutePalindrome(string s) {
        unsigned long long bitValue = 0ull;
        for (char c : s) 
            bitValue ^= 1ull << c-'A';
        return (bitValue & bitValue - 1ull) == 0ull;

Log in to reply

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