Python solution using bit manipulation

  • 0
            bitvec = 0
            for char in s:
                bitvec ^= (1 << ord(char))
            return bitvec == bitvec & (-bitvec)

    Using a bitvector to maintain each letter's odd/even status, and a bit trick to determine if there are more than one set bit in the bit vector (also returns true for 0 set bits).

Log in to reply

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